PaletteOptimiser

Changeset

108:854421107591
2015-10-11 Paul Boddie raw files shortlog changelog graph Attempt to use alternative colour combinations supplying the most pixels. simpleimage
optimiser.py (file)
     1.1 --- a/optimiser.py	Sun Oct 11 15:28:18 2015 +0200
     1.2 +++ b/optimiser.py	Sun Oct 11 15:56:31 2015 +0200
     1.3 @@ -307,17 +307,27 @@
     1.4      for y in range(0, height):
     1.5          c = get_colours(im, y)
     1.6  
     1.7 +        suggestions = []
     1.8 +
     1.9          for l in get_combinations(c, colours):
    1.10              most = [value for f, value in l]
    1.11 +            missing = 0
    1.12 +
    1.13              for x in range(0, width):
    1.14                  rgb = im.getpixel((x, y))
    1.15                  value = get_value(rgb, most, True)
    1.16                  if value is None:
    1.17 -                    break # try next combination
    1.18 -            else:
    1.19 +                    missing += 1
    1.20 +
    1.21 +            if not missing:
    1.22                  break # use this combination
    1.23 +            suggestions.append((missing, l))
    1.24 +
    1.25 +        # Find the most accurate suggestion.
    1.26 +
    1.27          else:
    1.28 -            most = [value for f, value in c[:colours]] # use the first colours
    1.29 +            suggestions.sort()
    1.30 +            most = [value for f, value in suggestions[0][1]] # get the combination
    1.31  
    1.32          for x in range(0, width):
    1.33              rgb = im.getpixel((x, y))