Merged _get_used_palette_colors into _get_optimize

This commit is contained in:
Andrew Murray 2017-01-26 14:17:20 +11:00
parent 4df1305073
commit ce87310026

View File

@ -557,19 +557,14 @@ 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)
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
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_color_table_size(palette_bytes):