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

BUG: add writeable_output=True to pillow plugin to ensure data is writable by default #976

Merged
merged 5 commits into from
Apr 28, 2023

Conversation

FirefoxMetzger
Copy link
Contributor

Closes: #877, #972

This PR adds the writeable_output kwarg to pillow's read and iter functions. If set to True (default) the plugin will ensure that the returned numpy array is writable, i.e., it will copy the data into a new buffer in cases where pillow would have otherwise returned a read-only array. This has the advantage of allowing in-place modifications of the returned array which makes the plugin backward compatible with v2 and is supposedly less surprising behavior.

It does come with a performance penalty though because we may have to copy the pixel data of a (potentially large) image. If, however, read-only is sufficient, e.g., when we copy the decoded data straight into an image batch (aka. image tensor) this extra copy is unnecessary. In such cases, users can set writeable_output=False. The plugin is then allowed to return read-only arrays if this is faster and users can enjoy improved performance.

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

Successfully merging this pull request may close these issues.

Array returned from image.imread in 2.28 is not writeable anymore imageio.v3.imread returns read-only array
1 participant