# HG changeset patch # User Paul Boddie # Date 1444420703 -7200 # Node ID 92dade31295323c9972c62a1de810d7123730c74 # Parent a02bebefc205122dccb09ba49cb427444e5ed9dc Propagate errors to horizontally-adjacent pixels for nicer dithering. diff -r a02bebefc205 -r 92dade312953 optimiser.py --- a/optimiser.py Fri Oct 09 19:01:18 2015 +0200 +++ b/optimiser.py Fri Oct 09 21:58:23 2015 +0200 @@ -39,7 +39,7 @@ return min(max(v, lower), upper) def clip(v): - return within(v, 0, 255) + return int(within(v, 0, 255)) def distance(rgb1, rgb2): r1, g1, b1 = rgb1 @@ -392,9 +392,14 @@ value = get_value(rgb, most) im.putpixel((x, y), value) + if x < width - 1: + rgbn = im.getpixel((x+1, y)) + rgbn = tuple(map(lambda i: clip(i[0] + (i[1] - i[2]) / 4.0), zip(rgbn, rgb, value))) + im.putpixel((x+1, y), rgbn) + if y < height - 1: rgbn = im.getpixel((x, y+1)) - rgbn = tuple(map(lambda i: clip(i[0] + i[1] - i[2]), zip(rgbn, rgb, value))) + rgbn = tuple(map(lambda i: clip(i[0] + (i[1] - i[2]) / 2.0), zip(rgbn, rgb, value))) im.putpixel((x, y+1), rgbn) im.save(output_filename)