1.1 --- a/optimiserlib.py Sun Oct 11 18:07:59 2015 +0200
1.2 +++ b/optimiserlib.py Sun Oct 11 19:12:15 2015 +0200
1.3 @@ -181,7 +181,8 @@
1.4
1.5 width, height = im.size
1.6 c = {}
1.7 - for x in range(0, width):
1.8 + x = 0
1.9 + while x < width:
1.10 rgb = im.getpixel((x, y))
1.11
1.12 # Sum the colour probabilities.
1.13 @@ -192,6 +193,8 @@
1.14 else:
1.15 c[value] += f
1.16
1.17 + x += 1
1.18 +
1.19 d = [(n/width, value) for value, n in c.items()]
1.20 d.sort(reverse=True)
1.21 return d
1.22 @@ -222,12 +225,16 @@
1.23
1.24 width, height = im.size
1.25
1.26 - for y in range(0, height):
1.27 + y = 0
1.28 + while y < height:
1.29 l = set()
1.30 - for x in range(0, width):
1.31 + x = 0
1.32 + while x < width:
1.33 l.add(im.getpixel((x, y)))
1.34 + x += 1
1.35 if len(l) > colours:
1.36 return (y, l)
1.37 + y += 1
1.38 return None
1.39
1.40 def process_image(im, saturate, desaturate, darken, brighten):
1.41 @@ -240,14 +247,18 @@
1.42 width, height = im.size
1.43
1.44 if saturate or desaturate or darken or brighten:
1.45 - for y in range(0, height):
1.46 - for x in range(0, width):
1.47 + y = 0
1.48 + while y < height:
1.49 + x = 0
1.50 + while x < width:
1.51 rgb = im.getpixel((x, y))
1.52 if saturate or desaturate:
1.53 rgb = saturate_rgb(rgb, saturate and 0.5 / saturate or 2.0 * desaturate)
1.54 if darken or brighten:
1.55 rgb = amplify_rgb(rgb, brighten and 0.5 / brighten or 2.0 * darken)
1.56 im.putpixel((x, y), rgb)
1.57 + x += 1
1.58 + y += 1
1.59
1.60 def convert_image(im, colours):
1.61
1.62 @@ -255,7 +266,8 @@
1.63
1.64 width, height = im.size
1.65
1.66 - for y in range(0, height):
1.67 + y = 0
1.68 + while y < height:
1.69 c = get_colours(im, y)
1.70
1.71 suggestions = []
1.72 @@ -264,11 +276,13 @@
1.73 most = [value for f, value in l]
1.74 missing = 0
1.75
1.76 - for x in range(0, width):
1.77 + x = 0
1.78 + while x < width:
1.79 rgb = im.getpixel((x, y))
1.80 value = get_value(rgb, most, True)
1.81 if value is None:
1.82 missing += 1
1.83 + x += 1
1.84
1.85 if not missing:
1.86 break # use this combination
1.87 @@ -280,7 +294,8 @@
1.88 suggestions.sort()
1.89 most = [value for f, value in suggestions[0][1]] # get the combination
1.90
1.91 - for x in range(0, width):
1.92 + x = 0
1.93 + while x < width:
1.94 rgb = im.getpixel((x, y))
1.95 value = get_value(rgb, most)
1.96 im.putpixel((x, y), value)
1.97 @@ -303,6 +318,10 @@
1.98 )
1.99 im.putpixel((x, y+1), rgbn)
1.100
1.101 + x += 1
1.102 +
1.103 + y += 1
1.104 +
1.105 class SimpleImage:
1.106
1.107 "An image behaving like PIL.Image."