PaletteOptimiser

Change of optimiser.py

91:4e37f510ccfd
optimiser.py simpleimage-shedskin
     1.1 --- a/optimiser.py	Sat Oct 10 16:48:46 2015 +0200
     1.2 +++ b/optimiser.py	Sat Oct 10 18:13:07 2015 +0200
     1.3 @@ -72,53 +72,6 @@
     1.4  
     1.5      return im.resize((width, height))
     1.6  
     1.7 -def convert_image(pim):
     1.8 -
     1.9 -    "Convert image 'pim' to an appropriate output representation."
    1.10 -
    1.11 -    width, height = pim.size
    1.12 -    im = SimpleImage(list(pim.getdata()), pim.size)
    1.13 -
    1.14 -    for y in range(0, height):
    1.15 -        c = get_colours(im, y)
    1.16 -
    1.17 -        for l in get_combinations(c, 4):
    1.18 -            most = [value for f, value in l]
    1.19 -            for x in range(0, width):
    1.20 -                rgb = im.getpixel((x, y))
    1.21 -                value = get_value(rgb, most, True)
    1.22 -                if value is None:
    1.23 -                    break # try next combination
    1.24 -            else:
    1.25 -                break # use this combination
    1.26 -        else:
    1.27 -            most = [value for f, value in c[:4]] # use the first four
    1.28 -
    1.29 -        for x in range(0, width):
    1.30 -            rgb = im.getpixel((x, y))
    1.31 -            value = get_value(rgb, most)
    1.32 -            im.putpixel((x, y), value)
    1.33 -
    1.34 -            if x < width - 1:
    1.35 -                rgbn = im.getpixel((x+1, y))
    1.36 -                rgbn = (
    1.37 -                    clip(rgbn[0] + (rgb[0] - value[0]) / 4.0),
    1.38 -                    clip(rgbn[1] + (rgb[1] - value[1]) / 4.0),
    1.39 -                    clip(rgbn[2] + (rgb[2] - value[2]) / 4.0)
    1.40 -                    )
    1.41 -                im.putpixel((x+1, y), rgbn)
    1.42 -
    1.43 -            if y < height - 1:
    1.44 -                rgbn = im.getpixel((x, y+1))
    1.45 -                rgbn = (
    1.46 -                    clip(rgbn[0] + (rgb[0] - value[0]) / 2.0),
    1.47 -                    clip(rgbn[1] + (rgb[1] - value[1]) / 2.0),
    1.48 -                    clip(rgbn[2] + (rgb[2] - value[2]) / 2.0)
    1.49 -                    )
    1.50 -                im.putpixel((x, y+1), rgbn)
    1.51 -
    1.52 -    pim.putdata(im.getdata())
    1.53 -
    1.54  def get_float(options, flag):
    1.55      try:
    1.56          i = options.index(flag)
    1.57 @@ -208,7 +161,9 @@
    1.58      # Generate an output image if requested.
    1.59  
    1.60      if make_image:
    1.61 -        convert_image(im)
    1.62 +        sim = SimpleImage(list(im.getdata()), im.size)
    1.63 +        convert_image(sim)
    1.64 +        im.putdata(sim.getdata())
    1.65          im.save(output_filename)
    1.66  
    1.67      # Verify the output image (which may be loaded) if requested.