Merge pull request #6567 from radarhere/palette

This commit is contained in:
Hugo van Kemenade 2022-09-24 13:27:41 +03:00 committed by GitHub
commit b7353af610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,15 +50,24 @@ class ImagePalette:
@palette.setter @palette.setter
def palette(self, palette): def palette(self, palette):
self._colors = None
self._palette = palette self._palette = palette
mode_len = len(self.mode) @property
self.colors = {} def colors(self):
for i in range(0, len(self.palette), mode_len): if self._colors is None:
color = tuple(self.palette[i : i + mode_len]) mode_len = len(self.mode)
if color in self.colors: self._colors = {}
continue for i in range(0, len(self.palette), mode_len):
self.colors[color] = i // mode_len color = tuple(self.palette[i : i + mode_len])
if color in self._colors:
continue
self._colors[color] = i // mode_len
return self._colors
@colors.setter
def colors(self, colors):
self._colors = colors
def copy(self): def copy(self):
new = ImagePalette() new = ImagePalette()