diff --git a/Tests/test_image.py b/Tests/test_image.py index 0e085d6e4..214f2668f 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -582,6 +582,10 @@ class TestImage: assert ext_individual == ext_multiple def test_remap_palette(self): + # Test identity transform + with Image.open("Tests/images/hopper.gif") as im: + assert_image_equal(im, im.remap_palette(list(range(256)))) + # Test illegal image mode with hopper() as im: with pytest.raises(ValueError): diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 76814a8cc..f06d3bdbc 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1796,6 +1796,7 @@ class Image: if source_palette is None: if self.mode == "P": + self.load() real_source_palette = self.im.getpalette("RGB")[:768] else: # L-mode real_source_palette = bytearray(i // 3 for i in range(768))