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

Attempt memory mapping when tile args is a string #7565

Merged
merged 1 commit into from Dec 21, 2023

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Nov 21, 2023

Here is the logic used to determine whether or not to try memory mapping.

Pillow/src/PIL/ImageFile.py

Lines 187 to 195 in 9694cfc

if use_mmap:
# try memory mapping
decoder_name, extents, offset, args = self.tile[0]
if (
decoder_name == "raw"
and len(args) >= 3
and args[0] == self.mode
and args[0] in Image._MAPMODES
):

It is expecting args to be a tuple, as in the following.

self.tile = [("raw", (0, 0) + self.size, offset, (rawmode, stride))]

However, here are a few place where the args for the "raw" tile is just a string.

self.tile = [("raw", (0, 0) + self.size, 0, "L")]

layer = mode[channel]
if mode == "CMYK":
layer += ";I"
tile.append(("raw", bbox, offset, layer))

self.tile = [("raw", (0, 0) + self.size, 0, self.mode)]

self.tile = [("raw", (0, 0) + self.size, 0, self.rawmode)]

So this PR updates the logic in ImageFile to allow for this possibility as well.

Testing it however, this causes WebPImagePlugin to start failing, so I've added load_seek to stop it attempting memory mapping.

@hugovk hugovk merged commit dd42a24 into python-pillow:main Dec 21, 2023
56 checks passed
@radarhere radarhere deleted the tile branch December 21, 2023 11:00
fdintino added a commit to fdintino/pillow-avif-plugin that referenced this pull request Jan 9, 2024
* fix: Convert EXIF orientation to AVIF irot and imir
* Disable mmap (see python-pillow/Pillow#7565)
* pin older cmake for python 2.7
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.

None yet

2 participants