PaletteOptimiser

Changeset

59:a64e7a0a3d33
2015-10-08 Paul Boddie raw files shortlog changelog graph Balancing is just simplifying the probabilities. Compensation is redundant: the balancing should have performed the necessary adjustments.
optimiser.py (file)
     1.1 --- a/optimiser.py	Thu Oct 08 23:37:29 2015 +0200
     1.2 +++ b/optimiser.py	Thu Oct 08 23:45:40 2015 +0200
     1.3 @@ -113,30 +113,12 @@
     1.4      """
     1.5  
     1.6      d = dict([(value, f) for f, value in d])
     1.7 -    for primary, secondary in map(complements, [(255, 0, 0), (0, 255, 0), (0, 0, 255)]):
     1.8 +    for primary, secondary in map(complements, [(0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255)]):
     1.9          common = min(d[primary], d[secondary])
    1.10          d[primary] -= common
    1.11          d[secondary] -= common
    1.12 -        d[(0, 0, 0)] += common
    1.13 -        d[(255, 255, 255)] += common
    1.14      return [(f, value) for value, f in d.items()]
    1.15  
    1.16 -def compensate(d, chosen):
    1.17 -
    1.18 -    """
    1.19 -    Compensate distribution 'd' for the given 'chosen' colours, reducing chosen
    1.20 -    colour contributions where their complements are not part of the chosen set.
    1.21 -    """
    1.22 -
    1.23 -    dd = dict([(value, f) for f, value in d])
    1.24 -    for f, value in d:
    1.25 -        if value in chosen:
    1.26 -            _value, complement = complements(value)
    1.27 -            if complement not in chosen:
    1.28 -                f = max(0, f - dd[complement])
    1.29 -                dd[value] = f
    1.30 -    return [(f, value) for value, f in dd.items() if value in chosen]
    1.31 -
    1.32  def combine(d):
    1.33  
    1.34      "Combine distribution 'd' to get a colour value."
    1.35 @@ -155,9 +137,7 @@
    1.36      specified 'chosen' colours.
    1.37      """
    1.38  
    1.39 -    l = combination(rgb)
    1.40 -    if chosen:
    1.41 -        l = compensate(l, chosen)
    1.42 +    l = [(f, value) for f, value in combination(rgb) if value in chosen]
    1.43      l.sort(reverse=True)
    1.44      return l
    1.45