From 90f3f72e1925622690d3d1e18dcae71ae794ba3e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 11 Jan 2022 13:30:51 +1100 Subject: [PATCH 1/3] Removed unused constant --- src/PIL/ImageMath.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py index 06bea800d..b4579081b 100644 --- a/src/PIL/ImageMath.py +++ b/src/PIL/ImageMath.py @@ -19,8 +19,6 @@ import builtins from . import Image, _imagingmath -VERBOSE = 0 - def _isconstant(v): return isinstance(v, (int, float)) From 9c6df29b4ddc9a065d6c7d5c451f21d9bb9af34a Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 11 Jan 2022 13:42:58 +1100 Subject: [PATCH 2/3] Removed unreachable error --- src/PIL/ImageMath.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py index b4579081b..8396148e8 100644 --- a/src/PIL/ImageMath.py +++ b/src/PIL/ImageMath.py @@ -67,8 +67,6 @@ class _Operand: im1 = im1.convert("F") if im2.mode != "F": im2 = im2.convert("F") - if im1.mode != im2.mode: - raise ValueError("mode mismatch") if im1.size != im2.size: # crop both arguments to a common size size = (min(im1.size[0], im2.size[0]), min(im1.size[1], im2.size[1])) From 01e7b3943d6ac4c208c3f6da8df27178e1e09155 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 11 Jan 2022 13:50:00 +1100 Subject: [PATCH 3/3] Simplified code --- src/PIL/ImageMath.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py index 8396148e8..4b6e4ccda 100644 --- a/src/PIL/ImageMath.py +++ b/src/PIL/ImageMath.py @@ -74,9 +74,7 @@ class _Operand: im1 = im1.crop((0, 0) + size) if im2.size != size: im2 = im2.crop((0, 0) + size) - out = Image.new(mode or im1.mode, size, None) - else: - out = Image.new(mode or im1.mode, im1.size, None) + out = Image.new(mode or im1.mode, im1.size, None) im1.load() im2.load() try: