Skip to content

Attempt memory mapping when tile args is a string#7565

Merged
hugovk merged 1 commit intopython-pillow:mainfrom
radarhere:tile
Dec 21, 2023
Merged

Attempt memory mapping when tile args is a string#7565
hugovk merged 1 commit intopython-pillow:mainfrom
radarhere:tile

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
@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

2 participants