When copying Image, copy ImagePalette as well

This commit is contained in:
Andrew Murray 2015-05-14 09:57:56 +10:00
parent ca89d431ba
commit b1e8a68df8
2 changed files with 14 additions and 1 deletions

View File

@ -509,7 +509,8 @@ class Image:
new.im = im
new.mode = im.mode
new.size = im.size
new.palette = self.palette
if self.palette:
new.palette = self.palette.copy()
if im.mode == "P" and not new.palette:
from PIL import ImagePalette
new.palette = ImagePalette.ImagePalette()

View File

@ -34,6 +34,18 @@ class ImagePalette:
(size != 0 and size != len(self.palette))):
raise ValueError("wrong palette size")
def copy(self):
new = ImagePalette()
new.mode = self.mode
new.rawmode = self.rawmode
if self.palette is not None:
new.palette = self.palette[:]
new.colors = self.colors.copy()
new.dirty = self.dirty
return new
def getdata(self):
"""
Get palette contents in format suitable # for the low-level