1.1 --- a/optimiser.py Wed Sep 30 18:19:47 2015 +0200
1.2 +++ b/optimiser.py Thu Oct 01 02:13:26 2015 +0200
1.3 @@ -65,6 +65,15 @@
1.4 def get_best(rgb, values):
1.5 return nearest(rgb, values)[0][1]
1.6
1.7 +def sign(x):
1.8 + return x >= 0 and 1 or -1
1.9 +
1.10 +def saturate(rgb):
1.11 + return tuple(map(saturate_value, rgb))
1.12 +
1.13 +def saturate_value(x):
1.14 + return 127.5 + sign(x - 127.5) * 127.5 * math.sqrt(abs(x - 127.5) / 127.5)
1.15 +
1.16 def test():
1.17 size = 512
1.18 for r in (0, 63, 127, 191, 255):
1.19 @@ -108,6 +117,7 @@
1.20
1.21 input_filename, output_filename = sys.argv[1:3]
1.22 rotate = "-r" in sys.argv[3:]
1.23 + saturate = "-s" in sys.argv[3:]
1.24
1.25 x = EXIF.process_file(open(input_filename))
1.26 im = PIL.Image.open(input_filename)
1.27 @@ -121,6 +131,8 @@
1.28 c = {}
1.29 for x in range(0, width):
1.30 rgb = im.getpixel((x, y))
1.31 + if saturate:
1.32 + rgb = saturate(rgb)
1.33 value = get_value((x, y), rgb, width, height)
1.34 im.putpixel((x, y), value)
1.35 if not c.has_key(value):