# HG changeset patch # User Paul Boddie # Date 1441751458 -7200 # Node ID 4e6369d60870699ec88401dbdf74e24b1c0e0f2a # Parent c1d09a02aa21e241e6e14d4f1bed05cb03656cdd Corrected some colour entries, added weighting for preferred tones. Added support for rotating the input image. diff -r c1d09a02aa21 -r 4e6369d60870 optimiser.py --- a/optimiser.py Wed Sep 09 00:07:25 2015 +0200 +++ b/optimiser.py Wed Sep 09 00:30:58 2015 +0200 @@ -35,20 +35,20 @@ return by_frequency(bases)[0] tones = [ - "___", "_BB", "BBB", "BBB", # 00x - "_GG", "_GC", "GGC", "GCC", # 01x - "GGG", "GGC", "GCC", "GCC", # 02x + "___", "_BB", "_BB", "BBB", # 00x + "_GG", "__C", "_BC", "BCC", # 01x + "_GG", "GGC", "BCC", "CCC", # 02x "GGG", "GCC", "CCC", "CCC", # 03x "_RR", "_MM", "MMB", "MBB", # 10x "_YY", "_**", "_*B", "BBW", # 11x - "GYY", "GGW", "GCC", "CCW", # 12x + "_GY", "GGC", "*CC", "CCW", # 12x "GGY", "GGG", "GCC", "CCW", # 13x "RRR", "RRM", "RMM", "MMM", # 20x "RYY", "RRW", "RMW", "MMW", # 21x "YYY", "YYW", "**W", "WWW", # 22x "YYY", "YYW", "YWW", "WWW", # 23x - "RRR", "RMM", "RMM", "MMM", # 30x - "RRY", "RRY", "RMM", "MMW", # 31x + "RRR", "RMM", "RMM", "MMW", # 30x + "RRY", "RRY", "RMW", "MMW", # 31x "YYY", "YYW", "YYW", "WWW", # 32x "YYY", "YYW", "YYW", "WWW", # 33x ] @@ -58,8 +58,11 @@ if __name__ == "__main__": width = 320 input_filename, output_filename = sys.argv[1:3] + rotate = "-r" in sys.argv[3:] im = PIL.Image.open(input_filename) + if rotate: + im = im.rotate(270) w, h = im.size height = (width * h) / w im = im.resize((width, height)) @@ -104,12 +107,17 @@ missing = [] tone_map = {} for tone, freq in u.items(): - base = match(tone[1], bases) or match(light and tone[2] or tone[0], bases) + base = match(tone[1], bases) if base: tone_map[tone] = base count += freq else: - missing.append(tone) + base = match(light and tone[2] or tone[0], bases) + if base: + tone_map[tone] = base + count += freq / 2 + else: + missing.append(tone) if count > best: best_bases = bases best_missing = missing