mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
When copying Image, copy ImagePalette as well
This commit is contained in:
parent
ca89d431ba
commit
b1e8a68df8
|
@ -509,7 +509,8 @@ class Image:
|
||||||
new.im = im
|
new.im = im
|
||||||
new.mode = im.mode
|
new.mode = im.mode
|
||||||
new.size = im.size
|
new.size = im.size
|
||||||
new.palette = self.palette
|
if self.palette:
|
||||||
|
new.palette = self.palette.copy()
|
||||||
if im.mode == "P" and not new.palette:
|
if im.mode == "P" and not new.palette:
|
||||||
from PIL import ImagePalette
|
from PIL import ImagePalette
|
||||||
new.palette = ImagePalette.ImagePalette()
|
new.palette = ImagePalette.ImagePalette()
|
||||||
|
|
|
@ -34,6 +34,18 @@ class ImagePalette:
|
||||||
(size != 0 and size != len(self.palette))):
|
(size != 0 and size != len(self.palette))):
|
||||||
raise ValueError("wrong palette size")
|
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):
|
def getdata(self):
|
||||||
"""
|
"""
|
||||||
Get palette contents in format suitable # for the low-level
|
Get palette contents in format suitable # for the low-level
|
||||||
|
|
Loading…
Reference in New Issue
Block a user