PaletteOptimiser

Change of optimiserlib.py

106:a879c7d1d28e
optimiserlib.py simpleimage-shedskin
     1.1 --- a/optimiserlib.py	Sun Oct 11 00:31:34 2015 +0200
     1.2 +++ b/optimiserlib.py	Sun Oct 11 15:34:12 2015 +0200
     1.3 @@ -249,28 +249,7 @@
     1.4                      rgb = amplify_rgb(rgb, brighten and 0.5 / brighten or 2.0 * darken)
     1.5                  im.putpixel((x, y), rgb)
     1.6  
     1.7 -def preview_image(im, half_resolution_preview=False):
     1.8 -
     1.9 -    "Return a preview copy of image 'im'."
    1.10 -
    1.11 -    width, height = im.size
    1.12 -    imp = im.copy()
    1.13 -    if half_resolution_preview:
    1.14 -        step = 2
    1.15 -    else:
    1.16 -        step = 1
    1.17 -
    1.18 -    for y in range(0, height):
    1.19 -        for x in range(0, width, step):
    1.20 -            rgb = im.getpixel((x, y))
    1.21 -            value = get_value(rgb)
    1.22 -            imp.putpixel((x, y), value)
    1.23 -            if half_resolution_preview:
    1.24 -                imp.putpixel((x+1, y), value)
    1.25 -
    1.26 -    return imp
    1.27 -
    1.28 -def convert_image(im):
    1.29 +def convert_image(im, colours):
    1.30  
    1.31      "Convert image 'im' to an appropriate output representation."
    1.32  
    1.33 @@ -279,7 +258,7 @@
    1.34      for y in range(0, height):
    1.35          c = get_colours(im, y)
    1.36  
    1.37 -        for l in get_combinations(c, 4):
    1.38 +        for l in get_combinations(c, colours):
    1.39              most = [value for f, value in l]
    1.40              for x in range(0, width):
    1.41                  rgb = im.getpixel((x, y))
    1.42 @@ -289,7 +268,7 @@
    1.43              else:
    1.44                  break # use this combination
    1.45          else:
    1.46 -            most = [value for f, value in c[:4]] # use the first four
    1.47 +            most = [value for f, value in c[:colours]] # use the first colours
    1.48  
    1.49          for x in range(0, width):
    1.50              rgb = im.getpixel((x, y))
    1.51 @@ -359,7 +338,6 @@
    1.52      count_colours(im, 4)
    1.53  
    1.54      process_image(im, 1.0, 0.0, 1.0, 0.0)
    1.55 -    preview_image(im, False)
    1.56 -    convert_image(im)
    1.57 +    convert_image(im, 4)
    1.58  
    1.59  # vim: tabstop=4 expandtab shiftwidth=4