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

Defer parsing of palette into colors #6567

Merged
merged 1 commit into from
Sep 24, 2022
Merged

Conversation

radarhere
Copy link
Member

Addresses #6561

The discussion points out that Image.fromarray(a, "P") is slower than Image.fromarray(a, "L"). The difference is that when fromarray calls frombuffer, for P mode an ImagePalette instance is created. Once ImagePalette assigns the initial palette, it parses the palette into a colors dictionary. This parsing is the main difference in speed.

I'm not convinced that Image.fromarray(a, "P") is a common enough to warrant speed optimization. However, the parsing of the initial ImagePalette palette string would be an operation shared through all P mode images, and depending on the series of operations from the user, colors is not necessarily used afterwards.

This PR defers the parsing of the palette into colors until the colors attribute is accessed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants