Skip to content

Commit

Permalink
Merge 1e231a3 into 80ac338
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 22, 2017
2 parents 80ac338 + 1e231a3 commit b63a316
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,18 +843,17 @@ def convert(self, mode=None, matrix=None, dither=None,
:returns: An :py:class:`~PIL.Image.Image` object.
"""

if not mode:
if not mode and self.mode == "P":
# determine default mode
if self.mode == "P":
self.load()
if self.palette:
mode = self.palette.mode
else:
mode = "RGB"
self.load()
if self.palette:
mode = self.palette.mode
else:
return self.copy()

self.load()
mode = "RGB"
elif not mode or (mode == self.mode and matrix is None):
return self.copy()
else:
self.load()

if matrix:
# matrix conversion
Expand Down Expand Up @@ -1038,10 +1037,10 @@ def crop(self, box=None):
:returns: An :py:class:`~PIL.Image.Image` object.
"""

self.load()
if box is None:
return self.copy()

self.load()
return self._new(self._crop(self.im, box))

def _crop(self, im, box):
Expand All @@ -1066,7 +1065,7 @@ def _crop(self, im, box):
_decompression_bomb_check((x1, y1))

return im.crop((x0, y0, x1, y1))

def draft(self, mode, size):
"""
Configures the image file loader so it returns a version of the
Expand Down Expand Up @@ -1363,9 +1362,10 @@ def paste(self, im, box=None, mask=None):
im = im.convert(self.mode)
im = im.im

self.load()
if self.readonly:
self._copy()
else:
self.load()

if mask:
mask.load()
Expand Down Expand Up @@ -1423,9 +1423,10 @@ def putalpha(self, alpha):
other color value.
"""

self.load()
if self.readonly:
self._copy()
else:
self.load()

if self.mode not in ("LA", "RGBA"):
# attempt to promote self to a matching alpha mode
Expand Down Expand Up @@ -1482,9 +1483,10 @@ def putdata(self, data, scale=1.0, offset=0.0):
:param offset: An optional offset value. The default is 0.0.
"""

self.load()
if self.readonly:
self._copy()
else:
self.load()

self.im.putdata(data, scale, offset)

Expand Down Expand Up @@ -1538,11 +1540,10 @@ def putpixel(self, xy, value):
:param value: The pixel value.
"""

self.load()
if self.readonly:
self._copy()
self.pyaccess = None
self.load()
self.load()

if self.pyaccess:
return self.pyaccess.putpixel(xy, value)
Expand Down

0 comments on commit b63a316

Please sign in to comment.