Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not attempt normalization if mode is already normal #6644

Merged
merged 1 commit into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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