# HG changeset patch # User Paul Boddie # Date 1444571761 -7200 # Node ID 8862d83bb344bcf2304feabc556be326ae784858 # Parent abb04ac9cf8d5df2bda7ccb05ce5655462d98216 Attempt to use alternative colour combinations supplying the most pixels. diff -r abb04ac9cf8d -r 8862d83bb344 optimiser.py --- a/optimiser.py Sun Oct 11 15:19:18 2015 +0200 +++ b/optimiser.py Sun Oct 11 15:56:01 2015 +0200 @@ -303,17 +303,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))