PaletteOptimiser

Changeset

80:9373e63a5e48
2015-10-10 Paul Boddie raw files shortlog changelog graph Merged repeated identical operation performance improvements. simpleimage
optimiser.py (file)
     1.1 --- a/optimiser.py	Sat Oct 10 14:58:40 2015 +0200
     1.2 +++ b/optimiser.py	Sat Oct 10 15:18:14 2015 +0200
     1.3 @@ -58,6 +58,9 @@
     1.4      r, g, b = srgb
     1.5      return 1.0 - r, 1.0 - g, 1.0 - b
     1.6  
     1.7 +scaled_corners = map(scale, corners)
     1.8 +zipped_corners = zip(corners, scaled_corners)
     1.9 +
    1.10  # Colour distribution functions.
    1.11  
    1.12  def combination(rgb):
    1.13 @@ -76,8 +79,8 @@
    1.14      # input colour.
    1.15  
    1.16      d = []
    1.17 -    for corner in corners:
    1.18 -        rs, gs, bs = scale(corner)
    1.19 +    for corner, scaled in zipped_corners:
    1.20 +        rs, gs, bs = scaled
    1.21  
    1.22          # Obtain inverted channel values where corner channels are low;
    1.23          # obtain original channel values where corner channels are high.
    1.24 @@ -95,6 +98,9 @@
    1.25      r, g, b = rgb
    1.26      return rgb, restore(invert(scale(rgb)))
    1.27  
    1.28 +bases = [(0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255)]
    1.29 +base_complements = map(complements, bases)
    1.30 +
    1.31  def balance(d):
    1.32  
    1.33      """
    1.34 @@ -103,7 +109,7 @@
    1.35      """
    1.36  
    1.37      d = dict([(value, f) for f, value in d])
    1.38 -    for primary, secondary in map(complements, [(0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255)]):
    1.39 +    for primary, secondary in base_complements:
    1.40          common = min(d[primary], d[secondary])
    1.41          d[primary] -= common
    1.42          d[secondary] -= common