mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 16:07:30 +03:00 
			
		
		
		
	Defer parsing of palette into colors
This commit is contained in:
		
							parent
							
								
									d843759ca9
								
							
						
					
					
						commit
						2a7e603ae2
					
				|  | @ -50,15 +50,24 @@ class ImagePalette: | |||
| 
 | ||||
|     @palette.setter | ||||
|     def palette(self, palette): | ||||
|         self._colors = None | ||||
|         self._palette = palette | ||||
| 
 | ||||
|     @property | ||||
|     def colors(self): | ||||
|         if self._colors is None: | ||||
|             mode_len = len(self.mode) | ||||
|         self.colors = {} | ||||
|             self._colors = {} | ||||
|             for i in range(0, len(self.palette), mode_len): | ||||
|                 color = tuple(self.palette[i : i + mode_len]) | ||||
|             if color in self.colors: | ||||
|                 if color in self._colors: | ||||
|                     continue | ||||
|             self.colors[color] = i // mode_len | ||||
|                 self._colors[color] = i // mode_len | ||||
|         return self._colors | ||||
| 
 | ||||
|     @colors.setter | ||||
|     def colors(self, colors): | ||||
|         self._colors = colors | ||||
| 
 | ||||
|     def copy(self): | ||||
|         new = ImagePalette() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user