Only call _get_used_palette_colors when necessary

This commit is contained in:
Andrew Murray 2017-01-26 15:27:43 +11:00
parent bf0b4cf279
commit 4df1305073

View File

@ -555,12 +555,12 @@ def _get_optimize(im, info):
# * If we have a 'large' image, the palette is in the noise. # * If we have a 'large' image, the palette is in the noise.
# create the new palette if not every color is used # create the new palette if not every color is used
used_palette_colors = _get_used_palette_colors(im) optimise = _FORCE_OPTIMIZE or im.mode == 'L'
if _FORCE_OPTIMIZE or im.mode == 'L' or \ if optimise or im.width * im.height < 512 * 512:
(len(used_palette_colors) <= 128 and used_palette_colors = _get_used_palette_colors(im)
max(used_palette_colors) > len(used_palette_colors) and if optimise or (len(used_palette_colors) <= 128 and
im.width * im.height < 512 * 512): max(used_palette_colors) > len(used_palette_colors)):
return used_palette_colors return used_palette_colors
def _get_used_palette_colors(im): def _get_used_palette_colors(im):
used_palette_colors = [] used_palette_colors = []