Do not attempt normalization if image is already normal

This commit is contained in:
Andrew Murray 2022-10-07 09:48:56 +11:00
parent 243402e78e
commit b8cd3e72a6
2 changed files with 10 additions and 1 deletions

View File

@ -38,6 +38,12 @@ def test_sanity():
convert(im, output_mode)
def test_unsupported_conversion():
im = hopper()
with pytest.raises(ValueError):
im.convert("INVALID")
def test_default():
im = hopper("P")

View File

@ -1036,7 +1036,10 @@ class Image:
except ValueError:
try:
# normalize source image and try again
im = self.im.convert(getmodebase(self.mode))
modebase = getmodebase(self.mode)
if modebase == self.mode:
raise
im = self.im.convert(modebase)
im = im.convert(mode, dither)
except KeyError as e:
raise ValueError("illegal conversion") from e