1.1 --- a/optimiser.py Fri Oct 09 14:20:02 2015 +0200
1.2 +++ b/optimiser.py Fri Oct 09 18:33:22 2015 +0200
1.3 @@ -2,7 +2,7 @@
1.4
1.5 """
1.6 Convert and optimise images for display in an Acorn Electron MODE 1 variant
1.7 -with four colours per line but eight colours available for selection for each
1.8 +with four colours per line but eight colours available for selection on each
1.9 line.
1.10
1.11 Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
1.12 @@ -35,8 +35,6 @@
1.13
1.14 # Basic colour operations.
1.15
1.16 -def extra(x): return x
1.17 -
1.18 def within(v, lower, upper):
1.19 return min(max(v, lower), upper)
1.20
1.21 @@ -54,9 +52,6 @@
1.22 def scale(rgb):
1.23 return tuple(map(lambda x: x / 255.0, rgb))
1.24
1.25 -def square(srgb):
1.26 - return tuple(map(lambda x: pow(x, 2), srgb))
1.27 -
1.28 def invert(srgb):
1.29 return tuple(map(lambda x: 1.0 - x, srgb))
1.30
1.31 @@ -69,7 +64,7 @@
1.32 # Get the colour with components scaled from 0 to 1, plus the inverted
1.33 # component values.
1.34
1.35 - rgb = extra(scale(rgb))
1.36 + rgb = scale(rgb)
1.37 rgbi = invert(rgb)
1.38 pairs = zip(rgbi, rgb)
1.39
1.40 @@ -302,11 +297,10 @@
1.41
1.42 Options are...
1.43
1.44 --s - Saturate the input image (can be repeated)
1.45 --d - Desaturate the input image (can be repeated)
1.46 +-s - Saturate the input image (can be followed by a float, default 1.0)
1.47 +-d - Desaturate the input image (can be followed by a float, default 1.0)
1.48 -D - Darken the input image (can be followed by a float, default 1.0)
1.49 -B - Brighten the input image (can be followed by a float, default 1.0)
1.50 --2 - Square/diminish the bright corner colour contributions (experimental)
1.51
1.52 -r - Rotate the input image clockwise
1.53 -p - Generate a separate preview image
1.54 @@ -327,17 +321,11 @@
1.55
1.56 # Preprocessing options that can be repeated for extra effect.
1.57
1.58 - saturate = options.count("-s")
1.59 - desaturate = options.count("-d")
1.60 + saturate = get_float(options, "-s")
1.61 + desaturate = get_float(options, "-d")
1.62 darken = get_float(options, "-D")
1.63 brighten = get_float(options, "-B")
1.64
1.65 - # Experimental colour distribution modification.
1.66 -
1.67 - use_square = "-2" in options
1.68 - if use_square:
1.69 - extra = square
1.70 -
1.71 # General output options.
1.72
1.73 rotate = "-r" in options
1.74 @@ -361,7 +349,7 @@
1.75 for x in range(0, width):
1.76 rgb = im.getpixel((x, y))
1.77 if saturate or desaturate:
1.78 - rgb = saturate_rgb(rgb, saturate and math.pow(0.5, saturate) or math.pow(2, desaturate))
1.79 + rgb = saturate_rgb(rgb, saturate and 0.5 / saturate or 2 * desaturate)
1.80 if darken or brighten:
1.81 rgb = amplify_rgb(rgb, brighten and 0.5 / brighten or 2 * darken)
1.82 im.putpixel((x, y), rgb)