mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-30 23:47:27 +03:00 
			
		
		
		
	Allow rawmode None to return the palette in the current mode
This commit is contained in:
		
							parent
							
								
									852859476b
								
							
						
					
					
						commit
						6be87277f7
					
				|  | @ -25,9 +25,10 @@ def test_palette_rawmode(): | ||||||
|     im = Image.new("P", (1, 1)) |     im = Image.new("P", (1, 1)) | ||||||
|     im.putpalette((1, 2, 3)) |     im.putpalette((1, 2, 3)) | ||||||
| 
 | 
 | ||||||
|     rgb = im.getpalette("RGB") |     for rawmode in ("RGB", None): | ||||||
|     assert len(rgb) == 256 * 3 |         rgb = im.getpalette(rawmode) | ||||||
|     assert rgb[:3] == [1, 2, 3] |         assert len(rgb) == 256 * 3 | ||||||
|  |         assert rgb[:3] == [1, 2, 3] | ||||||
| 
 | 
 | ||||||
|     # Convert the RGB palette to RGBA |     # Convert the RGB palette to RGBA | ||||||
|     rgba = im.getpalette("RGBA") |     rgba = im.getpalette("RGBA") | ||||||
|  | @ -41,6 +42,7 @@ def test_palette_rawmode(): | ||||||
|     assert len(rgb) == 256 * 3 |     assert len(rgb) == 256 * 3 | ||||||
|     assert rgb[:3] == [1, 2, 3] |     assert rgb[:3] == [1, 2, 3] | ||||||
| 
 | 
 | ||||||
|     rgba = im.getpalette("RGBA") |     for rawmode in ("RGBA", None): | ||||||
|     assert len(rgba) == 256 * 4 |         rgba = im.getpalette(rawmode) | ||||||
|     assert rgba[:4] == [1, 2, 3, 4] |         assert len(rgba) == 256 * 4 | ||||||
|  |         assert rgba[:4] == [1, 2, 3, 4] | ||||||
|  |  | ||||||
|  | @ -1405,7 +1405,8 @@ class Image: | ||||||
|         """ |         """ | ||||||
|         Returns the image palette as a list. |         Returns the image palette as a list. | ||||||
| 
 | 
 | ||||||
|         :param rawmode: The mode in which to return the palette. |         :param rawmode: The mode in which to return the palette. ``None`` will | ||||||
|  |            return the palette in its current mode. | ||||||
|         :returns: A list of color values [r, g, b, ...], or None if the |         :returns: A list of color values [r, g, b, ...], or None if the | ||||||
|            image has no palette. |            image has no palette. | ||||||
|         """ |         """ | ||||||
|  | @ -1415,6 +1416,8 @@ class Image: | ||||||
|             mode = self.im.getpalettemode() |             mode = self.im.getpalettemode() | ||||||
|         except ValueError: |         except ValueError: | ||||||
|             return None  # no palette |             return None  # no palette | ||||||
|  |         if rawmode is None: | ||||||
|  |             rawmode = mode | ||||||
|         return list(self.im.getpalette(mode, rawmode)) |         return list(self.im.getpalette(mode, rawmode)) | ||||||
| 
 | 
 | ||||||
|     def getpixel(self, xy): |     def getpixel(self, xy): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user