From ce87310026bd2ed7db570b9ba455cf1250f69e88 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 26 Jan 2017 14:17:20 +1100 Subject: [PATCH] Merged _get_used_palette_colors into _get_optimize --- PIL/GifImagePlugin.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index f27371181..9428590bc 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -557,21 +557,16 @@ def _get_optimize(im, info): # create the new palette if not every color is used optimise = _FORCE_OPTIMIZE or im.mode == 'L' if optimise or im.width * im.height < 512 * 512: - used_palette_colors = _get_used_palette_colors(im) + # check which colors are used + used_palette_colors = [] + for i, count in enumerate(im.histogram()): + if count: + used_palette_colors.append(i) + if optimise or (len(used_palette_colors) <= 128 and max(used_palette_colors) > len(used_palette_colors)): return used_palette_colors -def _get_used_palette_colors(im): - used_palette_colors = [] - - # check which colors are used - for i, count in enumerate(im.histogram()): - if count: - used_palette_colors.append(i) - - return used_palette_colors - def _get_color_table_size(palette_bytes): # calculate the palette size for the header import math