PaletteOptimiser

Change of dither.py

29:21c5d47536ea
dither.py
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dither.py	Fri Oct 02 19:22:17 2015 +0200
     1.3 @@ -0,0 +1,24 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +import PIL.Image
     1.7 +import sys
     1.8 +
     1.9 +def get_palette():
    1.10 +    l = []
    1.11 +    for i in range(0, 8):
    1.12 +        r = ((i / 4) % 2) * 255; g = ((i / 2) % 2) * 255; b = (i % 2) * 255
    1.13 +        for j in range(0, 32):
    1.14 +            l.extend((r, g, b))
    1.15 +
    1.16 +    imp = PIL.Image.new("P", (1, 1))
    1.17 +    imp.putpalette(l)
    1.18 +    return imp
    1.19 +
    1.20 +def dither(im, imp=None):
    1.21 +    return im.quantize(palette=imp or get_palette())
    1.22 +
    1.23 +im = PIL.Image.open(sys.argv[1])
    1.24 +im2 = dither(im)
    1.25 +im2.save(sys.argv[2])
    1.26 +
    1.27 +# vim: tabstop=4 expandtab shiftwidth=4