# HG changeset patch # User Paul Boddie # Date 1444340740 -7200 # Node ID a64e7a0a3d333c9be11d441671036655fdee7b7e # Parent 3be0716ebf8fcf2ac7b109921ea06f5249ab6a05 Balancing is just simplifying the probabilities. Compensation is redundant: the balancing should have performed the necessary adjustments. diff -r 3be0716ebf8f -r a64e7a0a3d33 optimiser.py --- a/optimiser.py Thu Oct 08 23:37:29 2015 +0200 +++ b/optimiser.py Thu Oct 08 23:45:40 2015 +0200 @@ -113,30 +113,12 @@ """ d = dict([(value, f) for f, value in d]) - for primary, secondary in map(complements, [(255, 0, 0), (0, 255, 0), (0, 0, 255)]): + for primary, secondary in map(complements, [(0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255)]): common = min(d[primary], d[secondary]) d[primary] -= common d[secondary] -= common - d[(0, 0, 0)] += common - d[(255, 255, 255)] += common return [(f, value) for value, f in d.items()] -def compensate(d, chosen): - - """ - Compensate distribution 'd' for the given 'chosen' colours, reducing chosen - colour contributions where their complements are not part of the chosen set. - """ - - dd = dict([(value, f) for f, value in d]) - for f, value in d: - if value in chosen: - _value, complement = complements(value) - if complement not in chosen: - f = max(0, f - dd[complement]) - dd[value] = f - return [(f, value) for value, f in dd.items() if value in chosen] - def combine(d): "Combine distribution 'd' to get a colour value." @@ -155,9 +137,7 @@ specified 'chosen' colours. """ - l = combination(rgb) - if chosen: - l = compensate(l, chosen) + l = [(f, value) for f, value in combination(rgb) if value in chosen] l.sort(reverse=True) return l