mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-29 02:34:10 +03:00
Added _mutable method for common code
This commit is contained in:
parent
23a51a35e9
commit
411765a69c
21
PIL/Image.py
21
PIL/Image.py
|
@ -592,6 +592,12 @@ class Image(object):
|
||||||
self.pyaccess = None
|
self.pyaccess = None
|
||||||
self.readonly = 0
|
self.readonly = 0
|
||||||
|
|
||||||
|
def _mutable(self):
|
||||||
|
if self.readonly:
|
||||||
|
self._copy()
|
||||||
|
else:
|
||||||
|
self.load()
|
||||||
|
|
||||||
def _dump(self, file=None, format=None, **options):
|
def _dump(self, file=None, format=None, **options):
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
@ -1390,10 +1396,7 @@ class Image(object):
|
||||||
im = im.convert(self.mode)
|
im = im.convert(self.mode)
|
||||||
im = im.im
|
im = im.im
|
||||||
|
|
||||||
if self.readonly:
|
self._mutable()
|
||||||
self._copy()
|
|
||||||
else:
|
|
||||||
self.load()
|
|
||||||
|
|
||||||
if mask:
|
if mask:
|
||||||
mask.load()
|
mask.load()
|
||||||
|
@ -1499,10 +1502,7 @@ class Image(object):
|
||||||
other color value.
|
other color value.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.readonly:
|
self._mutable()
|
||||||
self._copy()
|
|
||||||
else:
|
|
||||||
self.load()
|
|
||||||
|
|
||||||
if self.mode not in ("LA", "RGBA"):
|
if self.mode not in ("LA", "RGBA"):
|
||||||
# attempt to promote self to a matching alpha mode
|
# attempt to promote self to a matching alpha mode
|
||||||
|
@ -1558,10 +1558,7 @@ class Image(object):
|
||||||
:param offset: An optional offset value. The default is 0.0.
|
:param offset: An optional offset value. The default is 0.0.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.readonly:
|
self._mutable()
|
||||||
self._copy()
|
|
||||||
else:
|
|
||||||
self.load()
|
|
||||||
|
|
||||||
self.im.putdata(data, scale, offset)
|
self.im.putdata(data, scale, offset)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user