From ecb64fe2103b9393fd5cf77d3965504e1749ce6d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 8 Feb 2022 09:12:01 +1100 Subject: [PATCH] Allow 1 mode images to be inverted --- Tests/test_imageops.py | 1 + src/PIL/ImageOps.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/test_imageops.py b/Tests/test_imageops.py index 6aa1cf35edf..87fffa7b724 100644 --- a/Tests/test_imageops.py +++ b/Tests/test_imageops.py @@ -63,6 +63,7 @@ def test_sanity(): ImageOps.grayscale(hopper("L")) ImageOps.grayscale(hopper("RGB")) + ImageOps.invert(hopper("1")) ImageOps.invert(hopper("L")) ImageOps.invert(hopper("RGB")) diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index b170e9d8cc9..86db777d98c 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -523,7 +523,7 @@ def invert(image): lut = [] for i in range(256): lut.append(255 - i) - return _lut(image, lut) + return image.point(lut) if image.mode == "1" else _lut(image, lut) def mirror(image):