PaletteOptimiser

Changeset

38:594282e85848
2015-10-04 Paul Boddie raw files shortlog changelog graph Introduced random colour exchange when too many colours are needed.
optimiser.py (file)
     1.1 --- a/optimiser.py	Sat Oct 03 19:08:11 2015 +0200
     1.2 +++ b/optimiser.py	Sun Oct 04 00:32:47 2015 +0200
     1.3 @@ -1,6 +1,6 @@
     1.4  #!/usr/bin/env python
     1.5  
     1.6 -from random import random
     1.7 +from random import random, randrange
     1.8  from os.path import splitext
     1.9  import EXIF
    1.10  import PIL.Image
    1.11 @@ -188,11 +188,11 @@
    1.12          most = [value for n, value in c[:4]]
    1.13          least = [value for n, value in c[4:]]
    1.14  
    1.15 -        #if least:
    1.16 -        #    if (0, 0, 0) in least[:2]:
    1.17 -        #        replace((0, 0, 0), most)
    1.18 -        #    if (255, 255, 255) in least[:2]:
    1.19 -        #        replace((255, 255, 255), most)
    1.20 +        if least:
    1.21 +            i = randrange(4, len(c))
    1.22 +            c = c[:3] + c[i:i+1] + c[4:i] + c[i+1:]
    1.23 +            most = [value for n, value in c[:4]]
    1.24 +            least = [value for n, value in c[4:]]
    1.25  
    1.26          for x in range(0, width):
    1.27              rgb = im.getpixel((x, y))