mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 16:07:30 +03:00 
			
		
		
		
	Do not redeclare class each time when converting to NumPy
This commit is contained in:
		
							parent
							
								
									e1eefe4486
								
							
						
					
					
						commit
						83c42fcabd
					
				|  | @ -656,6 +656,10 @@ class Image: | |||
|             raise ValueError("Could not save to PNG for display") from e | ||||
|         return b.getvalue() | ||||
| 
 | ||||
|     class _ArrayData: | ||||
|         def __init__(self, new): | ||||
|             self.__array_interface__ = new | ||||
| 
 | ||||
|     def __array__(self, dtype=None): | ||||
|         # numpy array interface support | ||||
|         import numpy as np | ||||
|  | @ -672,10 +676,7 @@ class Image: | |||
|         else: | ||||
|             new["data"] = self.tobytes() | ||||
| 
 | ||||
|         class ArrayData: | ||||
|             __array_interface__ = new | ||||
| 
 | ||||
|         return np.array(ArrayData(), dtype) | ||||
|         return np.array(self._ArrayData(new), dtype) | ||||
| 
 | ||||
|     def __getstate__(self): | ||||
|         return [self.info, self.mode, self.size, self.getpalette(), self.tobytes()] | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user