1.1 --- a/optimiser.py Wed Oct 07 00:49:40 2015 +0200
1.2 +++ b/optimiser.py Wed Oct 07 01:21:07 2015 +0200
1.3 @@ -17,7 +17,7 @@
1.4 return min(max(v, lower), upper)
1.5
1.6 def clip(v):
1.7 - return within(v, 0, 255)
1.8 + return int(within(v, 0, 255))
1.9
1.10 def distance(rgb1, rgb2):
1.11 r1, g1, b1 = rgb1
1.12 @@ -249,9 +249,14 @@
1.13 im.putpixel((x, y), value)
1.14
1.15 if y < height - 1:
1.16 - rgbn = im.getpixel((x, y+1))
1.17 - rgbn = tuple(map(lambda i: clip(i[0] + i[1] - i[2]), zip(rgbn, rgb, value)))
1.18 - im.putpixel((x, y+1), rgbn)
1.19 +
1.20 + # Spread the error across adjacent pixels.
1.21 +
1.22 + error = tuple(map(lambda i: (i[0] - i[1]) / 2.0, zip(rgb, value)))
1.23 + for xn in range(x, min(x + 2, width)):
1.24 + rgbn = im.getpixel((xn, y+1))
1.25 + rgbn = tuple(map(lambda i: clip(i[0] + i[1]), zip(rgbn, error)))
1.26 + im.putpixel((xn, y+1), rgbn)
1.27
1.28 im.save(output_filename)
1.29