mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 17:54:32 +03:00
Fixed palette for LA and PA mode when pickling
This commit is contained in:
parent
7cc1be167c
commit
e9c0cf61f3
|
@ -75,6 +75,15 @@ class TestPickle(PillowTestCase):
|
||||||
protocol=protocol,
|
protocol=protocol,
|
||||||
test_file=test_file)
|
test_file=test_file)
|
||||||
|
|
||||||
|
def test_pickle_pa_mode(self):
|
||||||
|
# Arrange
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
for protocol in range(0, pickle.HIGHEST_PROTOCOL + 1):
|
||||||
|
self.helper_pickle_string(pickle, protocol, mode="PA")
|
||||||
|
self.helper_pickle_file(pickle, protocol, mode="PA")
|
||||||
|
|
||||||
def test_pickle_l_mode(self):
|
def test_pickle_l_mode(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
import pickle
|
import pickle
|
||||||
|
@ -84,6 +93,24 @@ class TestPickle(PillowTestCase):
|
||||||
self.helper_pickle_string(pickle, protocol, mode="L")
|
self.helper_pickle_string(pickle, protocol, mode="L")
|
||||||
self.helper_pickle_file(pickle, protocol, mode="L")
|
self.helper_pickle_file(pickle, protocol, mode="L")
|
||||||
|
|
||||||
|
def test_pickle_la_mode_with_palette(self):
|
||||||
|
# Arrange
|
||||||
|
import pickle
|
||||||
|
im = Image.open('Tests/images/hopper.jpg')
|
||||||
|
filename = self.tempfile('temp.pkl')
|
||||||
|
im = im.convert("PA")
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
for protocol in range(0, pickle.HIGHEST_PROTOCOL + 1):
|
||||||
|
im.mode = "LA"
|
||||||
|
with open(filename, 'wb') as f:
|
||||||
|
pickle.dump(im, f, protocol)
|
||||||
|
with open(filename, 'rb') as f:
|
||||||
|
loaded_im = pickle.load(f)
|
||||||
|
|
||||||
|
im.mode = "PA"
|
||||||
|
self.assertEqual(im, loaded_im)
|
||||||
|
|
||||||
def test_cpickle_l_mode(self):
|
def test_cpickle_l_mode(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -715,7 +715,7 @@ class Image(object):
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self._size = size
|
self._size = size
|
||||||
self.im = core.new(mode, size)
|
self.im = core.new(mode, size)
|
||||||
if mode in ("L", "P") and palette:
|
if mode in ("L", "LA", "P", "PA") and palette:
|
||||||
self.putpalette(palette)
|
self.putpalette(palette)
|
||||||
self.frombytes(data)
|
self.frombytes(data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user