mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-25 08:10:33 +03:00
Clarify check that palette is not already at its smallest
This commit is contained in:
parent
709744432a
commit
847ad8c512
|
@ -830,9 +830,13 @@ def _get_optimize(im, info):
|
|||
num_palette_colors = len(im.palette.palette) // Image.getmodebands(
|
||||
im.palette.mode
|
||||
)
|
||||
# Round up to power of 2 but at least 4
|
||||
num_palette_colors = max(4, 1 << (num_palette_colors - 1).bit_length())
|
||||
if len(used_palette_colors) <= num_palette_colors // 2:
|
||||
current_palette_size = 1 << (num_palette_colors - 1).bit_length()
|
||||
if (
|
||||
# check that the palette would become smaller when saved
|
||||
len(used_palette_colors) <= current_palette_size // 2
|
||||
# check that the palette is not already the smallest possible size
|
||||
and current_palette_size > 2
|
||||
):
|
||||
return used_palette_colors
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user