mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-15 11:00:52 +03:00
bytearray as preferred palette storage
This commit is contained in:
parent
3c2e374824
commit
c6489e6fb7
|
@ -38,7 +38,7 @@ class ImagePalette(object):
|
|||
def __init__(self, mode="RGB", palette=None, size=0):
|
||||
self.mode = mode
|
||||
self.rawmode = None # if set, palette contains raw data
|
||||
self.palette = palette or list(range(256))*len(self.mode)
|
||||
self.palette = palette or bytearray(range(256))*len(self.mode)
|
||||
self.colors = {}
|
||||
self.dirty = None
|
||||
if ((size == 0 and len(self.mode)*256 != len(self.palette)) or
|
||||
|
@ -98,8 +98,7 @@ class ImagePalette(object):
|
|||
except KeyError:
|
||||
# allocate new color slot
|
||||
if isinstance(self.palette, bytes):
|
||||
self.palette = [(ord(x) if str is bytes else int(x))
|
||||
for x in self.palette]
|
||||
self.palette = bytearray(self.palette)
|
||||
index = len(self.colors)
|
||||
if index >= 256:
|
||||
raise ValueError("cannot allocate more than 256 colors")
|
||||
|
|
Loading…
Reference in New Issue
Block a user