# HG changeset patch # User Paul Boddie # Date 1443828746 -7200 # Node ID da4132364cfd8e838b5020c2a0f04375d87813ec # Parent 3a950efbc68f8f732a92692ce0166b06ed712d71 Experiment with replacing colours with black and white. diff -r 3a950efbc68f -r da4132364cfd optimiser.py --- a/optimiser.py Sat Oct 03 00:32:58 2015 +0200 +++ b/optimiser.py Sat Oct 03 01:32:26 2015 +0200 @@ -52,6 +52,13 @@ def saturate_value(x, exp): return int(127.5 + sign(x - 127.5) * 127.5 * pow(abs(x - 127.5) / 127.5, exp)) +def replace(value, values): + if value not in values: + for i, v in list(enumerate(values))[::-1]: + if v != value: + values[i] = value + return + def test(): size = 512 for r in (0, 63, 127, 191, 255): @@ -135,6 +142,12 @@ most = [value for n, value in c[:4]] least = [value for n, value in c[4:]] + if least: + if (0, 0, 0) in least[:2]: + replace((0, 0, 0), most) + if (255, 255, 255) in least[:2]: + replace((255, 255, 255), most) + for x in range(0, width): rgb = im.getpixel((x, y)) @@ -144,7 +157,7 @@ value = get_value(rgb) if value in least: rgb = im.getpixel((x, y)) - value = pattern(value, most)[0][1] + value = get_value(value, most) im.putpixel((x, y), value)