We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ImageChops: logical_and produces "Image has wrong mode" with 2 RGB images
### What did you do?
I tried to apply logical_and between two RGB images

### What did you expect to happen?
AND function pixel-by-pixel, color-by-color

### What actually happened?
"Image has wrong mode" message. According to the docs, 
"At this time, most channel operations are only implemented for 8-bit images (e.g. “L” and “RGB”)."

### What versions of Pillow and Python are you using?
Python 3.6.1, PIL 1.1.7

```python
from PIL import Image, ImageChops

def test_chops():
    img = Image.new("RGB", (100, 100), 0xffffff)
    new_img = ImageChops.logical_and(img, img)


def main():
    test_chops()
    return 0

main()
```


--- 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/ImageChops.py`
Content:
```
1 #
2 # The Python Imaging Library.
3 # $Id$
4 #
5 # standard channel operations
6 #
7 # History:
8 # 1996-03-24 fl   Created
9 # 1996-08-13 fl   Added logical operations (for "1" images)
10 # 2000-10-12 fl   Added offset method (from Image.py)
11 #
12 # Copyright (c) 1997-2000 by Secret Labs AB
13 # Copyright (c) 1996-2000 by Fredrik Lundh
14 #
15 # See the README file for information on usage and redistribution.
16 #
17 
18 from . import Image
19 
20 
21 def constant(image, value):
22     """Fill a channel with a given grey level.
23 
24     :rtype: :py:class:`~PIL.Image.Image`
25     """
26 
27     return Image.new("L", image.size, value)
28 
29 
30 def duplicate(image):
31     """Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`.
32 
33     :rtype: :py:class:`~PIL.Image.Image`
34     """
35 
36     return image.copy()
37 
38 
39 def invert(image):
40     """
41     Invert an image (channel).
42 
43     .. code-block:: python
44 
45         out = MAX - image
46 
47     :rtype: :py:class:`~PIL.Image.Image`
48     """
49 
50     image.load()
51     return image._new(image.im.chop_invert())
52 
53 
54 def lighter(image1, image2):
55     """
56     Compares the two images, pixel by pixel, and returns a new image containing
57     the lighter values.
58 
59     .. code-block:: python
60 
61         out = max(image1, image2)
62 
63     :rtype: :py:class:`~PIL.Image.Image`
64     """
65 
66     image1.load()
67     image2.load()
68     return image1._new(image1.im.chop_lighter(image2.im))
69 
70 
71 def darker(image1, image2):
72     """
73     Compares the two images, pixel by pixel, and returns a new image
74     containing the darker values.
75 
76     .. code-block:: python
77 
78         out = min(image1, image2)
79 
80     :rtype: :py:class:`~PIL.Image.Image`
81     """
82 
83     image1.load()
84     image2.load()
85     return image1._new(image1.im.chop_darker(image2.im))
86 
87 
88 def difference(image1, image2):
89     """
90     Returns the absolute value of the pixel-by-pixel difference between the two
91     images.
92 
93     .. code-block:: python
94 
95         out = abs(image1 - image2)
96 
97     :rtype: :py:class:`~PIL.Image.Image`
98     """
99 
100     image1.load()
101     image2.load()
102     return image1._new(image1.im.chop_difference(image2.im))
103 
104 
105 def multiply(image1, image2):
106     """
107     Superimposes two images on top of each other.
108 
109     If you multiply an image with a solid black image, the result is black. If
110     you multiply with a solid white image, the image is unaffected.
111 
112     .. code-block:: python
113 
114         out = image1 * image2 / MAX
115 
116     :rtype: :py:class:`~PIL.Image.Image`
117     """
118 
119     image1.load()
120     image2.load()
121     return image1._new(image1.im.chop_multiply(image2.im))
122 
123 
124 def screen(image1, image2):
125     """
126     Superimposes two inverted images on top of each other.
127 
128     .. code-block:: python
129 
130         out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
131 
132     :rtype: :py:class:`~PIL.Image.Image`
133     """
134 
135     image1.load()
136     image2.load()
137     return image1._new(image1.im.chop_screen(image2.im))
138 
139 
140 def add(image1, image2, scale=1.0, offset=0):
141     """
142     Adds two images, dividing the result by scale and adding the
143     offset. If omitted, scale defaults to 1.0, and offset to 0.0.
144 
145     .. code-block:: python
146 
147         out = ((image1 + image2) / scale + offset)
148 
149     :rtype: :py:class:`~PIL.Image.Image`
150     """
151 
152     image1.load()
153     image2.load()
154     return image1._new(image1.im.chop_add(image2.im, scale, offset))
155 
156 
157 def subtract(image1, image2, scale=1.0, offset=0):
158     """
159     Subtracts two images, dividing the result by scale and adding the
160     offset. If omitted, scale defaults to 1.0, and offset to 0.0.
161 
162     .. code-block:: python
163 
164         out = ((image1 - image2) / scale + offset)
165 
166     :rtype: :py:class:`~PIL.Image.Image`
167     """
168 
169     image1.load()
170     image2.load()
171     return image1._new(image1.im.chop_subtract(image2.im, scale, offset))
172 
173 
174 def add_modulo(image1, image2):
175     """Add two images, without clipping the result.
176 
177     .. code-block:: python
178 
179         out = ((image1 + image2) % MAX)
180 
181     :rtype: :py:class:`~PIL.Image.Image`
182     """
183 
184     image1.load()
185     image2.load()
186     return image1._new(image1.im.chop_add_modulo(image2.im))
187 
188 
189 def subtract_modulo(image1, image2):
190     """Subtract two images, without clipping the result.
191 
192     .. code-block:: python
193 
194         out = ((image1 - image2) % MAX)
195 
196     :rtype: :py:class:`~PIL.Image.Image`
197     """
198 
199     image1.load()
200     image2.load()
201     return image1._new(image1.im.chop_subtract_modulo(image2.im))
202 
203 
204 def logical_and(image1, image2):
205     """Logical AND between two images.
206 
207     .. code-block:: python
208 
209         out = ((image1 and image2) % MAX)
210 
211     :rtype: :py:class:`~PIL.Image.Image`
212     """
213 
214     image1.load()
215     image2.load()
216     return image1._new(image1.im.chop_and(image2.im))
217 
218 
219 def logical_or(image1, image2):
220     """Logical OR between two images.
221 
222     .. code-block:: python
223 
224         out = ((image1 or image2) % MAX)
225 
226     :rtype: :py:class:`~PIL.Image.Image`
227     """
228 
229     image1.load()
230     image2.load()
231     return image1._new(image1.im.chop_or(image2.im))
232 
233 
234 def logical_xor(image1, image2):
235     """Logical XOR between two images.
236 
237     .. code-block:: python
238 
239         out = ((bool(image1) != bool(image2)) % MAX)
240 
241     :rtype: :py:class:`~PIL.Image.Image`
242     """
243 
244     image1.load()
245     image2.load()
246     return image1._new(image1.im.chop_xor(image2.im))
247 
248 
249 def blend(image1, image2, alpha):
250     """Blend images using constant transparency weight. Alias for
251     :py:meth:`PIL.Image.Image.blend`.
252 
253     :rtype: :py:class:`~PIL.Image.Image`
254     """
255 
256     return Image.blend(image1, image2, alpha)
257 
258 
259 def composite(image1, image2, mask):
260     """Create composite using transparency mask. Alias for
261     :py:meth:`PIL.Image.Image.composite`.
262 
263     :rtype: :py:class:`~PIL.Image.Image`
264     """
265 
266     return Image.composite(image1, image2, mask)
267 
268 
269 def offset(image, xoffset, yoffset=None):
270     """Returns a copy of the image where data has been offset by the given
271     distances. Data wraps around the edges. If **yoffset** is omitted, it
272     is assumed to be equal to **xoffset**.
273 
274     :param xoffset: The horizontal distance.
275     :param yoffset: The vertical distance.  If omitted, both
276         distances are set to the same value.
277     :rtype: :py:class:`~PIL.Image.Image`
278     """
279 
280     if yoffset is None:
281         yoffset = xoffset
282     image.load()
283     return image._new(image.im.offset(xoffset, yoffset))
284
```
--- 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/ImageChops.py b/src/PIL/ImageChops.py
--- a/src/PIL/ImageChops.py
+++ b/src/PIL/ImageChops.py
@@ -54,7 +54,7 @@
 def lighter(image1, image2):
     """
     Compares the two images, pixel by pixel, and returns a new image containing
-    the lighter values.
+    the lighter values. At least one of the images must have mode "1".
 
     .. code-block:: python
 
@@ -70,8 +70,8 @@
 
 def darker(image1, image2):
     """
-    Compares the two images, pixel by pixel, and returns a new image
-    containing the darker values.
+    Compares the two images, pixel by pixel, and returns a new image containing
+    the darker values. At least one of the images must have mode "1".
 
     .. code-block:: python
 
@@ -88,7 +88,7 @@
 def difference(image1, image2):
     """
     Returns the absolute value of the pixel-by-pixel difference between the two
-    images.
+    images. At least one of the images must have mode "1".
 
     .. code-block:: python
 
@@ -107,7 +107,8 @@
     Superimposes two images on top of each other.
 
     If you multiply an image with a solid black image, the result is black. If
-    you multiply with a solid white image, the image is unaffected.
+    you multiply with a solid white image, the image is unaffected. At least
+    one of the images must have mode "1".
 
     .. code-block:: python
 
@@ -123,7 +124,8 @@
 
 def screen(image1, image2):
     """
-    Superimposes two inverted images on top of each other.
+    Superimposes two inverted images on top of each other. At least one of the
+    images must have mode "1".
 
     .. code-block:: python
 
@@ -141,6 +143,7 @@
     """
     Adds two images, dividing the result by scale and adding the
     offset. If omitted, scale defaults to 1.0, and offset to 0.0.
+    At least one of the images must have mode "1".
 
     .. code-block:: python
 
@@ -156,8 +159,9 @@
 
 def subtract(image1, image2, scale=1.0, offset=0):
     """
-    Subtracts two images, dividing the result by scale and adding the
-    offset. If omitted, scale defaults to 1.0, and offset to 0.0.
+    Subtracts two images, dividing the result by scale and adding the offset.
+    If omitted, scale defaults to 1.0, and offset to 0.0. At least one of the
+    images must have mode "1".
 
     .. code-block:: python
 
@@ -172,7 +176,8 @@
 
 
 def add_modulo(image1, image2):
-    """Add two images, without clipping the result.
+    """Add two images, without clipping the result. At least one of the images
+    must have mode "1".
 
     .. code-block:: python
 
@@ -187,7 +192,8 @@
 
 
 def subtract_modulo(image1, image2):
-    """Subtract two images, without clipping the result.
+    """Subtract two images, without clipping the result. At least one of the
+    images must have mode "1".
 
     .. code-block:: python
 
@@ -202,7 +208,8 @@
 
 
 def logical_and(image1, image2):
-    """Logical AND between two images.
+    """Logical AND between two images. At least one of the images must have
+    mode "1".
 
     .. code-block:: python
 
@@ -217,7 +224,8 @@
 
 
 def logical_or(image1, image2):
-    """Logical OR between two images.
+    """Logical OR between two images. At least one of the images must have
+    mode "1".
 
     .. code-block:: python
 
@@ -232,7 +240,8 @@
 
 
 def logical_xor(image1, image2):
-    """Logical XOR between two images.
+    """Logical XOR between two images. At least one of the images must have
+    mode "1".
 
     .. code-block:: python

{"golden_diff": "diff --git a/src/PIL/ImageChops.py b/src/PIL/ImageChops.py\n--- a/src/PIL/ImageChops.py\n+++ b/src/PIL/ImageChops.py\n@@ -54,7 +54,7 @@\n def lighter(image1, image2):\n     \"\"\"\n     Compares the two images, pixel by pixel, and returns a new image containing\n-    the lighter values.\n+    the lighter values. At least one of the images must have mode \"1\".\n \n     .. code-block:: python\n \n@@ -70,8 +70,8 @@\n \n def darker(image1, image2):\n     \"\"\"\n-    Compares the two images, pixel by pixel, and returns a new image\n-    containing the darker values.\n+    Compares the two images, pixel by pixel, and returns a new image containing\n+    the darker values. At least one of the images must have mode \"1\".\n \n     .. code-block:: python\n \n@@ -88,7 +88,7 @@\n def difference(image1, image2):\n     \"\"\"\n     Returns the absolute value of the pixel-by-pixel difference between the two\n-    images.\n+    images. At least one of the images must have mode \"1\".\n \n     .. code-block:: python\n \n@@ -107,7 +107,8 @@\n     Superimposes two images on top of each other.\n \n     If you multiply an image with a solid black image, the result is black. If\n-    you multiply with a solid white image, the image is unaffected.\n+    you multiply with a solid white image, the image is unaffected. At least\n+    one of the images must have mode \"1\".\n \n     .. code-block:: python\n \n@@ -123,7 +124,8 @@\n \n def screen(image1, image2):\n     \"\"\"\n-    Superimposes two inverted images on top of each other.\n+    Superimposes two inverted images on top of each other. At least one of the\n+    images must have mode \"1\".\n \n     .. code-block:: python\n \n@@ -141,6 +143,7 @@\n     \"\"\"\n     Adds two images, dividing the result by scale and adding the\n     offset. If omitted, scale defaults to 1.0, and offset to 0.0.\n+    At least one of the images must have mode \"1\".\n \n     .. code-block:: python\n \n@@ -156,8 +159,9 @@\n \n def subtract(image1, image2, scale=1.0, offset=0):\n     \"\"\"\n-    Subtracts two images, dividing the result by scale and adding the\n-    offset. If omitted, scale defaults to 1.0, and offset to 0.0.\n+    Subtracts two images, dividing the result by scale and adding the offset.\n+    If omitted, scale defaults to 1.0, and offset to 0.0. At least one of the\n+    images must have mode \"1\".\n \n     .. code-block:: python\n \n@@ -172,7 +176,8 @@\n \n \n def add_modulo(image1, image2):\n-    \"\"\"Add two images, without clipping the result.\n+    \"\"\"Add two images, without clipping the result. At least one of the images\n+    must have mode \"1\".\n \n     .. code-block:: python\n \n@@ -187,7 +192,8 @@\n \n \n def subtract_modulo(image1, image2):\n-    \"\"\"Subtract two images, without clipping the result.\n+    \"\"\"Subtract two images, without clipping the result. At least one of the\n+    images must have mode \"1\".\n \n     .. code-block:: python\n \n@@ -202,7 +208,8 @@\n \n \n def logical_and(image1, image2):\n-    \"\"\"Logical AND between two images.\n+    \"\"\"Logical AND between two images. At least one of the images must have\n+    mode \"1\".\n \n     .. code-block:: python\n \n@@ -217,7 +224,8 @@\n \n \n def logical_or(image1, image2):\n-    \"\"\"Logical OR between two images.\n+    \"\"\"Logical OR between two images. At least one of the images must have\n+    mode \"1\".\n \n     .. code-block:: python\n \n@@ -232,7 +240,8 @@\n \n \n def logical_xor(image1, image2):\n-    \"\"\"Logical XOR between two images.\n+    \"\"\"Logical XOR between two images. At least one of the images must have\n+    mode \"1\".\n \n     .. code-block:: python\n", "issue": "ImageChops: logical_and produces \"Image has wrong mode\" with 2 RGB images\n### What did you do?\r\nI tried to apply logical_and between two RGB images\r\n\r\n### What did you expect to happen?\r\nAND function pixel-by-pixel, color-by-color\r\n\r\n### What actually happened?\r\n\"Image has wrong mode\" message. According to the docs, \r\n\"At this time, most channel operations are only implemented for 8-bit images (e.g. \u201cL\u201d and \u201cRGB\u201d).\"\r\n\r\n### What versions of Pillow and Python are you using?\r\nPython 3.6.1, PIL 1.1.7\r\n\r\n```python\r\nfrom PIL import Image, ImageChops\r\n\r\ndef test_chops():\r\n    img = Image.new(\"RGB\", (100, 100), 0xffffff)\r\n    new_img = ImageChops.logical_and(img, img)\r\n\r\n\r\ndef main():\r\n    test_chops()\r\n    return 0\r\n\r\nmain()\r\n```\r\n\n", "before_files": [{"content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# standard channel operations\n#\n# History:\n# 1996-03-24 fl   Created\n# 1996-08-13 fl   Added logical operations (for \"1\" images)\n# 2000-10-12 fl   Added offset method (from Image.py)\n#\n# Copyright (c) 1997-2000 by Secret Labs AB\n# Copyright (c) 1996-2000 by Fredrik Lundh\n#\n# See the README file for information on usage and redistribution.\n#\n\nfrom . import Image\n\n\ndef constant(image, value):\n    \"\"\"Fill a channel with a given grey level.\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    return Image.new(\"L\", image.size, value)\n\n\ndef duplicate(image):\n    \"\"\"Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`.\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    return image.copy()\n\n\ndef invert(image):\n    \"\"\"\n    Invert an image (channel).\n\n    .. code-block:: python\n\n        out = MAX - image\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image.load()\n    return image._new(image.im.chop_invert())\n\n\ndef lighter(image1, image2):\n    \"\"\"\n    Compares the two images, pixel by pixel, and returns a new image containing\n    the lighter values.\n\n    .. code-block:: python\n\n        out = max(image1, image2)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_lighter(image2.im))\n\n\ndef darker(image1, image2):\n    \"\"\"\n    Compares the two images, pixel by pixel, and returns a new image\n    containing the darker values.\n\n    .. code-block:: python\n\n        out = min(image1, image2)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_darker(image2.im))\n\n\ndef difference(image1, image2):\n    \"\"\"\n    Returns the absolute value of the pixel-by-pixel difference between the two\n    images.\n\n    .. code-block:: python\n\n        out = abs(image1 - image2)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_difference(image2.im))\n\n\ndef multiply(image1, image2):\n    \"\"\"\n    Superimposes two images on top of each other.\n\n    If you multiply an image with a solid black image, the result is black. If\n    you multiply with a solid white image, the image is unaffected.\n\n    .. code-block:: python\n\n        out = image1 * image2 / MAX\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_multiply(image2.im))\n\n\ndef screen(image1, image2):\n    \"\"\"\n    Superimposes two inverted images on top of each other.\n\n    .. code-block:: python\n\n        out = MAX - ((MAX - image1) * (MAX - image2) / MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_screen(image2.im))\n\n\ndef add(image1, image2, scale=1.0, offset=0):\n    \"\"\"\n    Adds two images, dividing the result by scale and adding the\n    offset. If omitted, scale defaults to 1.0, and offset to 0.0.\n\n    .. code-block:: python\n\n        out = ((image1 + image2) / scale + offset)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_add(image2.im, scale, offset))\n\n\ndef subtract(image1, image2, scale=1.0, offset=0):\n    \"\"\"\n    Subtracts two images, dividing the result by scale and adding the\n    offset. If omitted, scale defaults to 1.0, and offset to 0.0.\n\n    .. code-block:: python\n\n        out = ((image1 - image2) / scale + offset)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_subtract(image2.im, scale, offset))\n\n\ndef add_modulo(image1, image2):\n    \"\"\"Add two images, without clipping the result.\n\n    .. code-block:: python\n\n        out = ((image1 + image2) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_add_modulo(image2.im))\n\n\ndef subtract_modulo(image1, image2):\n    \"\"\"Subtract two images, without clipping the result.\n\n    .. code-block:: python\n\n        out = ((image1 - image2) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_subtract_modulo(image2.im))\n\n\ndef logical_and(image1, image2):\n    \"\"\"Logical AND between two images.\n\n    .. code-block:: python\n\n        out = ((image1 and image2) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_and(image2.im))\n\n\ndef logical_or(image1, image2):\n    \"\"\"Logical OR between two images.\n\n    .. code-block:: python\n\n        out = ((image1 or image2) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_or(image2.im))\n\n\ndef logical_xor(image1, image2):\n    \"\"\"Logical XOR between two images.\n\n    .. code-block:: python\n\n        out = ((bool(image1) != bool(image2)) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_xor(image2.im))\n\n\ndef blend(image1, image2, alpha):\n    \"\"\"Blend images using constant transparency weight. Alias for\n    :py:meth:`PIL.Image.Image.blend`.\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    return Image.blend(image1, image2, alpha)\n\n\ndef composite(image1, image2, mask):\n    \"\"\"Create composite using transparency mask. Alias for\n    :py:meth:`PIL.Image.Image.composite`.\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    return Image.composite(image1, image2, mask)\n\n\ndef offset(image, xoffset, yoffset=None):\n    \"\"\"Returns a copy of the image where data has been offset by the given\n    distances. Data wraps around the edges. If **yoffset** is omitted, it\n    is assumed to be equal to **xoffset**.\n\n    :param xoffset: The horizontal distance.\n    :param yoffset: The vertical distance.  If omitted, both\n        distances are set to the same value.\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    if yoffset is None:\n        yoffset = xoffset\n    image.load()\n    return image._new(image.im.offset(xoffset, yoffset))\n", "path": "src/PIL/ImageChops.py"}], "after_files": [{"content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# standard channel operations\n#\n# History:\n# 1996-03-24 fl   Created\n# 1996-08-13 fl   Added logical operations (for \"1\" images)\n# 2000-10-12 fl   Added offset method (from Image.py)\n#\n# Copyright (c) 1997-2000 by Secret Labs AB\n# Copyright (c) 1996-2000 by Fredrik Lundh\n#\n# See the README file for information on usage and redistribution.\n#\n\nfrom . import Image\n\n\ndef constant(image, value):\n    \"\"\"Fill a channel with a given grey level.\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    return Image.new(\"L\", image.size, value)\n\n\ndef duplicate(image):\n    \"\"\"Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`.\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    return image.copy()\n\n\ndef invert(image):\n    \"\"\"\n    Invert an image (channel).\n\n    .. code-block:: python\n\n        out = MAX - image\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image.load()\n    return image._new(image.im.chop_invert())\n\n\ndef lighter(image1, image2):\n    \"\"\"\n    Compares the two images, pixel by pixel, and returns a new image containing\n    the lighter values. At least one of the images must have mode \"1\".\n\n    .. code-block:: python\n\n        out = max(image1, image2)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_lighter(image2.im))\n\n\ndef darker(image1, image2):\n    \"\"\"\n    Compares the two images, pixel by pixel, and returns a new image containing\n    the darker values. At least one of the images must have mode \"1\".\n\n    .. code-block:: python\n\n        out = min(image1, image2)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_darker(image2.im))\n\n\ndef difference(image1, image2):\n    \"\"\"\n    Returns the absolute value of the pixel-by-pixel difference between the two\n    images. At least one of the images must have mode \"1\".\n\n    .. code-block:: python\n\n        out = abs(image1 - image2)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_difference(image2.im))\n\n\ndef multiply(image1, image2):\n    \"\"\"\n    Superimposes two images on top of each other.\n\n    If you multiply an image with a solid black image, the result is black. If\n    you multiply with a solid white image, the image is unaffected. At least\n    one of the images must have mode \"1\".\n\n    .. code-block:: python\n\n        out = image1 * image2 / MAX\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_multiply(image2.im))\n\n\ndef screen(image1, image2):\n    \"\"\"\n    Superimposes two inverted images on top of each other. At least one of the\n    images must have mode \"1\".\n\n    .. code-block:: python\n\n        out = MAX - ((MAX - image1) * (MAX - image2) / MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_screen(image2.im))\n\n\ndef add(image1, image2, scale=1.0, offset=0):\n    \"\"\"\n    Adds two images, dividing the result by scale and adding the\n    offset. If omitted, scale defaults to 1.0, and offset to 0.0.\n    At least one of the images must have mode \"1\".\n\n    .. code-block:: python\n\n        out = ((image1 + image2) / scale + offset)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_add(image2.im, scale, offset))\n\n\ndef subtract(image1, image2, scale=1.0, offset=0):\n    \"\"\"\n    Subtracts two images, dividing the result by scale and adding the offset.\n    If omitted, scale defaults to 1.0, and offset to 0.0. At least one of the\n    images must have mode \"1\".\n\n    .. code-block:: python\n\n        out = ((image1 - image2) / scale + offset)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_subtract(image2.im, scale, offset))\n\n\ndef add_modulo(image1, image2):\n    \"\"\"Add two images, without clipping the result. At least one of the images\n    must have mode \"1\".\n\n    .. code-block:: python\n\n        out = ((image1 + image2) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_add_modulo(image2.im))\n\n\ndef subtract_modulo(image1, image2):\n    \"\"\"Subtract two images, without clipping the result. At least one of the\n    images must have mode \"1\".\n\n    .. code-block:: python\n\n        out = ((image1 - image2) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_subtract_modulo(image2.im))\n\n\ndef logical_and(image1, image2):\n    \"\"\"Logical AND between two images. At least one of the images must have\n    mode \"1\".\n\n    .. code-block:: python\n\n        out = ((image1 and image2) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_and(image2.im))\n\n\ndef logical_or(image1, image2):\n    \"\"\"Logical OR between two images. At least one of the images must have\n    mode \"1\".\n\n    .. code-block:: python\n\n        out = ((image1 or image2) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_or(image2.im))\n\n\ndef logical_xor(image1, image2):\n    \"\"\"Logical XOR between two images. At least one of the images must have\n    mode \"1\".\n\n    .. code-block:: python\n\n        out = ((bool(image1) != bool(image2)) % MAX)\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    image1.load()\n    image2.load()\n    return image1._new(image1.im.chop_xor(image2.im))\n\n\ndef blend(image1, image2, alpha):\n    \"\"\"Blend images using constant transparency weight. Alias for\n    :py:meth:`PIL.Image.Image.blend`.\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    return Image.blend(image1, image2, alpha)\n\n\ndef composite(image1, image2, mask):\n    \"\"\"Create composite using transparency mask. Alias for\n    :py:meth:`PIL.Image.Image.composite`.\n\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    return Image.composite(image1, image2, mask)\n\n\ndef offset(image, xoffset, yoffset=None):\n    \"\"\"Returns a copy of the image where data has been offset by the given\n    distances. Data wraps around the edges. If **yoffset** is omitted, it\n    is assumed to be equal to **xoffset**.\n\n    :param xoffset: The horizontal distance.\n    :param yoffset: The vertical distance.  If omitted, both\n        distances are set to the same value.\n    :rtype: :py:class:`~PIL.Image.Image`\n    \"\"\"\n\n    if yoffset is None:\n        yoffset = xoffset\n    image.load()\n    return image._new(image.im.offset(xoffset, yoffset))\n", "path": "src/PIL/ImageChops.py"}]}