# HG changeset patch # User Paul Boddie # Date 1444571791 -7200 # Node ID 854421107591382a6160f85f09a1c09792024e56 # Parent e5fce4442d7ea21c9b8fb376253794e21d71cba5# Parent 8862d83bb344bcf2304feabc556be326ae784858 Attempt to use alternative colour combinations supplying the most pixels. diff -r e5fce4442d7e -r 854421107591 optimiser.py --- a/optimiser.py Sun Oct 11 15:28:18 2015 +0200 +++ b/optimiser.py Sun Oct 11 15:56:31 2015 +0200 @@ -307,17 +307,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))