Skip to content

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