1.1 --- a/optimiser.py Sat Oct 10 16:41:10 2015 +0200
1.2 +++ b/optimiser.py Sat Oct 10 16:48:46 2015 +0200
1.3 @@ -72,26 +72,6 @@
1.4
1.5 return im.resize((width, height))
1.6
1.7 -def preview_image(pim, half_resolution_preview=False):
1.8 -
1.9 - "Return a preview copy of image 'pim'."
1.10 -
1.11 - width, height = pim.size
1.12 - imp = pim.copy()
1.13 - im = SimpleImage(list(pim.getdata()), pim.size)
1.14 - step = half_resolution_preview and 2 or 1
1.15 -
1.16 - for y in range(0, height):
1.17 - for x in range(0, width, step):
1.18 - rgb = im.getpixel((x, y))
1.19 - value = get_value(rgb)
1.20 - im.putpixel((x, y), value)
1.21 - if half_resolution_preview:
1.22 - im.putpixel((x+1, y), value)
1.23 -
1.24 - imp.putdata(im.getdata())
1.25 - return imp
1.26 -
1.27 def convert_image(pim):
1.28
1.29 "Convert image 'pim' to an appropriate output representation."
1.30 @@ -219,7 +199,11 @@
1.31 # Generate a preview if requested.
1.32
1.33 if preview:
1.34 - preview_image(im, half_resolution_preview).save(preview_filename)
1.35 + imp = im.copy()
1.36 + sim = SimpleImage(list(im.getdata()), im.size)
1.37 + simp = preview_image(sim, half_resolution_preview)
1.38 + imp.putdata(simp.getdata())
1.39 + imp.save(preview_filename)
1.40
1.41 # Generate an output image if requested.
1.42
2.1 --- a/optimiserlib.py Sat Oct 10 16:41:10 2015 +0200
2.2 +++ b/optimiserlib.py Sat Oct 10 16:48:46 2015 +0200
2.3 @@ -249,6 +249,27 @@
2.4 rgb = amplify_rgb(rgb, brighten and 0.5 / brighten or 2 * darken)
2.5 im.putpixel((x, y), rgb)
2.6
2.7 +def preview_image(im, half_resolution_preview=False):
2.8 +
2.9 + "Return a preview copy of image 'im'."
2.10 +
2.11 + width, height = im.size
2.12 + imp = im.copy()
2.13 + if half_resolution_preview:
2.14 + step = 2
2.15 + else:
2.16 + step = 1
2.17 +
2.18 + for y in range(0, height):
2.19 + for x in range(0, width, step):
2.20 + rgb = im.getpixel((x, y))
2.21 + value = get_value(rgb)
2.22 + imp.putpixel((x, y), value)
2.23 + if half_resolution_preview:
2.24 + imp.putpixel((x+1, y), value)
2.25 +
2.26 + return imp
2.27 +
2.28 class SimpleImage:
2.29
2.30 "An image behaving like PIL.Image."
2.31 @@ -294,5 +315,6 @@
2.32 count_colours(im, 4)
2.33
2.34 process_image(im, 1.0, 0.0, 1.0, 0.0)
2.35 + preview_image(im, False)
2.36
2.37 # vim: tabstop=4 expandtab shiftwidth=4