mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-09 23:04:45 +03:00
If Image is created directly, add missing core image when loading
This commit is contained in:
parent
4ecf1df4ea
commit
a129937cf5
|
@ -94,6 +94,18 @@ class TestImage:
|
||||||
# with pytest.raises(MemoryError):
|
# with pytest.raises(MemoryError):
|
||||||
# Image.new("L", (1000000, 1000000))
|
# Image.new("L", (1000000, 1000000))
|
||||||
|
|
||||||
|
def test_direct(self):
|
||||||
|
# Test that a directly instantiated Image()
|
||||||
|
# is given a core image during load()
|
||||||
|
im = Image.Image()
|
||||||
|
assert im.im is None
|
||||||
|
|
||||||
|
im.load()
|
||||||
|
assert im.im is not None
|
||||||
|
|
||||||
|
# Test equality
|
||||||
|
assert Image.Image() == Image.Image()
|
||||||
|
|
||||||
def test_repr_pretty(self):
|
def test_repr_pretty(self):
|
||||||
class Pretty:
|
class Pretty:
|
||||||
def text(self, text):
|
def text(self, text):
|
||||||
|
|
|
@ -826,6 +826,10 @@ class Image:
|
||||||
:returns: An image access object.
|
:returns: An image access object.
|
||||||
:rtype: :ref:`PixelAccess` or :py:class:`PIL.PyAccess`
|
:rtype: :ref:`PixelAccess` or :py:class:`PIL.PyAccess`
|
||||||
"""
|
"""
|
||||||
|
if self._mode == "":
|
||||||
|
# This image was instantiated directly
|
||||||
|
self._mode = "1"
|
||||||
|
self.im = core.new(self.mode, self.size)
|
||||||
if self.im is not None and self.palette and self.palette.dirty:
|
if self.im is not None and self.palette and self.palette.dirty:
|
||||||
# realize palette
|
# realize palette
|
||||||
mode, arr = self.palette.getdata()
|
mode, arr = self.palette.getdata()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user