Skip to content

Commit

Permalink
Do not attempt normalization if image is already normal
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Oct 6, 2022
1 parent 243402e commit b8cd3e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Tests/test_image_convert.py
Expand Up @@ -38,6 +38,12 @@ def convert(im, mode):
convert(im, output_mode)


def test_unsupported_conversion():
im = hopper()
with pytest.raises(ValueError):
im.convert("INVALID")


def test_default():

im = hopper("P")
Expand Down
5 changes: 4 additions & 1 deletion src/PIL/Image.py
Expand Up @@ -1036,7 +1036,10 @@ def convert_transparency(m, v):
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
Expand Down

0 comments on commit b8cd3e7

Please sign in to comment.