# HG changeset patch # User Paul Boddie # Date 1444579679 -7200 # Node ID 904b2295aca58e32e8eef4378028065140ed81dd # Parent a879c7d1d28e7f47144169d350ace2ea3e341880# Parent 854421107591382a6160f85f09a1c09792024e56 Attempt to use alternative colour combinations supplying the most pixels. diff -r a879c7d1d28e -r 904b2295aca5 optimiser.py diff -r a879c7d1d28e -r 904b2295aca5 optimiserlib.py --- a/optimiserlib.py Sun Oct 11 15:34:12 2015 +0200 +++ b/optimiserlib.py Sun Oct 11 18:07:59 2015 +0200 @@ -258,17 +258,27 @@ for y in range(0, height): c = get_colours(im, y) + suggestions = [] + for l in get_combinations(c, colours): most = [value for f, value in l] + missing = 0 + for x in range(0, width): rgb = im.getpixel((x, y)) value = get_value(rgb, most, True) if value is None: - break # try next combination - else: + missing += 1 + + if not missing: break # use this combination + suggestions.append((missing, l)) + + # Find the most accurate suggestion. + else: - most = [value for f, value in c[:colours]] # use the first colours + suggestions.sort() + most = [value for f, value in suggestions[0][1]] # get the combination for x in range(0, width): rgb = im.getpixel((x, y))