PaletteOptimiser

Changeset

65:6890aa1afe3e
2015-10-09 Paul Boddie raw files shortlog changelog graph Changed darken/brighten to use numeric parameters.
optimiser.py (file)
     1.1 --- a/optimiser.py	Fri Oct 09 01:30:38 2015 +0200
     1.2 +++ b/optimiser.py	Fri Oct 09 12:04:16 2015 +0200
     1.3 @@ -274,6 +274,16 @@
     1.4              return (y, l)
     1.5      return None
     1.6  
     1.7 +def get_float(options, flag):
     1.8 +    try:
     1.9 +        i = options.index(flag)
    1.10 +        if options[i+1].isdigit():
    1.11 +            return float(options[i+1])
    1.12 +        else:
    1.13 +            return 1.0
    1.14 +    except ValueError:
    1.15 +        return 0.0
    1.16 +
    1.17  # Main program.
    1.18  
    1.19  if __name__ == "__main__":
    1.20 @@ -294,8 +304,8 @@
    1.21  
    1.22  -s - Saturate the input image (can be repeated)
    1.23  -d - Desaturate the input image (can be repeated)
    1.24 --D - Darken the input image (can be repeated or followed by a float)
    1.25 --B - Brighten the input image (can be repeated or followed by a float)
    1.26 +-D - Darken the input image (can be followed by a float, default 1.0)
    1.27 +-B - Brighten the input image (can be followed by a float, default 1.0)
    1.28  -2 - Square/diminish the bright corner colour contributions (experimental)
    1.29  
    1.30  -r - Rotate the input image clockwise
    1.31 @@ -319,17 +329,8 @@
    1.32  
    1.33      saturate = options.count("-s")
    1.34      desaturate = options.count("-d")
    1.35 -    darken = options.count("-D")
    1.36 -    brighten = options.count("-B")
    1.37 -
    1.38 -    if darken == 1:
    1.39 -        i = options.index("-D")
    1.40 -        if options[i+1].isdigit():
    1.41 -            darken = float(options[i+1])
    1.42 -    if brighten == 1:
    1.43 -        i = options.index("-B")
    1.44 -        if options[i+1].isdigit():
    1.45 -            brighten = float(options[i+1])
    1.46 +    darken = get_float(options, "-D")
    1.47 +    brighten = get_float(options, "-B")
    1.48  
    1.49      # Experimental colour distribution modification.
    1.50