2.1 --- a/optimiserlib.py Sun Oct 11 15:34:12 2015 +0200
2.2 +++ b/optimiserlib.py Sun Oct 11 18:07:59 2015 +0200
2.3 @@ -258,17 +258,27 @@
2.4 for y in range(0, height):
2.5 c = get_colours(im, y)
2.6
2.7 + suggestions = []
2.8 +
2.9 for l in get_combinations(c, colours):
2.10 most = [value for f, value in l]
2.11 + missing = 0
2.12 +
2.13 for x in range(0, width):
2.14 rgb = im.getpixel((x, y))
2.15 value = get_value(rgb, most, True)
2.16 if value is None:
2.17 - break # try next combination
2.18 - else:
2.19 + missing += 1
2.20 +
2.21 + if not missing:
2.22 break # use this combination
2.23 + suggestions.append((missing, l))
2.24 +
2.25 + # Find the most accurate suggestion.
2.26 +
2.27 else:
2.28 - most = [value for f, value in c[:colours]] # use the first colours
2.29 + suggestions.sort()
2.30 + most = [value for f, value in suggestions[0][1]] # get the combination
2.31
2.32 for x in range(0, width):
2.33 rgb = im.getpixel((x, y))