Do not use use built-in mapper WIN32 only

This commit is contained in:
Christoph Gohlke 2019-12-27 01:28:11 -08:00 committed by GitHub
parent 00b9303edc
commit 39876cf1bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -178,24 +178,16 @@ class ImageFile(Image.Image):
and args[0] in Image._MAPMODES and args[0] in Image._MAPMODES
): ):
try: try:
if hasattr(Image.core, "map"): # use mmap, if possible
# use built-in mapper WIN32 only import mmap
self.map = Image.core.map(self.filename)
self.map.seek(offset)
self.im = self.map.readimage(
self.mode, self.size, args[1], args[2]
)
else:
# use mmap, if possible
import mmap
with open(self.filename, "r") as fp: with open(self.filename, "r") as fp:
self.map = mmap.mmap( self.map = mmap.mmap(
fp.fileno(), 0, access=mmap.ACCESS_READ fp.fileno(), 0, access=mmap.ACCESS_READ
)
self.im = Image.core.map_buffer(
self.map, self.size, decoder_name, extents, offset, args
) )
self.im = Image.core.map_buffer(
self.map, self.size, decoder_name, extents, offset, args
)
readonly = 1 readonly = 1
# After trashing self.im, # After trashing self.im,
# we might need to reload the palette data. # we might need to reload the palette data.