# HG changeset patch # User Paul Boddie # Date 1444483011 -7200 # Node ID e0fe30d7b8b13f2108857d313baa3dae2a1235fd # Parent b147df07482fe86e9479a8979ba3e17de41fb577 Perform processing giving identical results only once. diff -r b147df07482f -r e0fe30d7b8b1 optimiser.py --- a/optimiser.py Sat Oct 10 14:57:16 2015 +0200 +++ b/optimiser.py Sat Oct 10 15:16:51 2015 +0200 @@ -58,6 +58,9 @@ r, g, b = srgb return 1.0 - r, 1.0 - g, 1.0 - b +scaled_corners = map(scale, corners) +zipped_corners = zip(corners, scaled_corners) + # Colour distribution functions. def combination(rgb): @@ -76,8 +79,8 @@ # input colour. d = [] - for corner in corners: - rs, gs, bs = scale(corner) + for corner, scaled in zipped_corners: + rs, gs, bs = scaled # Obtain inverted channel values where corner channels are low; # obtain original channel values where corner channels are high. @@ -95,6 +98,9 @@ r, g, b = rgb return rgb, restore(invert(scale(rgb))) +bases = [(0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255)] +base_complements = map(complements, bases) + def balance(d): """ @@ -103,7 +109,7 @@ """ d = dict([(value, f) for f, value in d]) - for primary, secondary in map(complements, [(0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255)]): + for primary, secondary in base_complements: common = min(d[primary], d[secondary]) d[primary] -= common d[secondary] -= common