Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow remap_palette() to return an image with less than 256 palette entries #6543

Merged
merged 1 commit into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Tests/test_image.py
Expand Up @@ -620,6 +620,7 @@ def test_remap_palette_transparency(self):

im_remapped = im.remap_palette([1, 0])
assert im_remapped.info["transparency"] == 1
assert len(im_remapped.getpalette()) == 6

# Test unused transparency
im.info["transparency"] = 2
Expand Down
6 changes: 1 addition & 5 deletions src/PIL/Image.py
Expand Up @@ -1944,11 +1944,7 @@ def remap_palette(self, dest_map, source_palette=None):

m_im = m_im.convert("L")

# Internally, we require 256 palette entries.
new_palette_bytes = (
palette_bytes + ((256 * bands) - len(palette_bytes)) * b"\x00"
)
m_im.putpalette(new_palette_bytes, palette_mode)
m_im.putpalette(palette_bytes, palette_mode)
m_im.palette = ImagePalette.ImagePalette(palette_mode, palette=palette_bytes)

if "transparency" in self.info:
Expand Down