mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Fix scrambled XPM image, don't mmap when load_read/load_seek is defined. Fixes #806
This commit is contained in:
parent
14d1ac6389
commit
d30eb007ef
|
@ -133,11 +133,27 @@ class ImageFile(Image.Image):
|
|||
return pixel
|
||||
|
||||
self.map = None
|
||||
|
||||
use_mmap = self.filename and len(self.tile) == 1
|
||||
# As of pypy 2.1.0, memory mapping was failing here.
|
||||
use_mmap = use_mmap and not hasattr(sys, 'pypy_version_info')
|
||||
|
||||
readonly = 0
|
||||
|
||||
if self.filename and len(self.tile) == 1 and not hasattr(sys, 'pypy_version_info'):
|
||||
# As of pypy 2.1.0, memory mapping was failing here.
|
||||
# look for read/seek overrides
|
||||
try:
|
||||
read = self.load_read
|
||||
# don't use mmap if there are custom read/seek functions
|
||||
use_mmap = False
|
||||
except AttributeError:
|
||||
read = self.fp.read
|
||||
|
||||
try:
|
||||
seek = self.load_seek
|
||||
use_mmap = False
|
||||
except AttributeError:
|
||||
seek = self.fp.seek
|
||||
|
||||
if use_mmap:
|
||||
# try memory mapping
|
||||
d, e, o, a = self.tile[0]
|
||||
if d == "raw" and a[0] == self.mode and a[0] in Image._MAPMODES:
|
||||
|
@ -165,19 +181,7 @@ class ImageFile(Image.Image):
|
|||
|
||||
self.load_prepare()
|
||||
|
||||
# look for read/seek overrides
|
||||
try:
|
||||
read = self.load_read
|
||||
except AttributeError:
|
||||
read = self.fp.read
|
||||
|
||||
try:
|
||||
seek = self.load_seek
|
||||
except AttributeError:
|
||||
seek = self.fp.seek
|
||||
|
||||
if not self.map:
|
||||
|
||||
# sort tiles in file order
|
||||
self.tile.sort(key=_tilesort)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from helper import unittest, PillowTestCase, lena
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
@ -15,6 +15,9 @@ class TestFileXpm(PillowTestCase):
|
|||
self.assertEqual(im.size, (128, 128))
|
||||
self.assertEqual(im.format, "XPM")
|
||||
|
||||
#large error due to quantization->44 colors.
|
||||
self.assert_image_similar(im.convert('RGB'), lena('RGB'), 60)
|
||||
|
||||
def test_load_read(self):
|
||||
# Arrange
|
||||
im = Image.open(TEST_FILE)
|
||||
|
|
Loading…
Reference in New Issue
Block a user