# HG changeset patch # User Paul Boddie # Date 1444408402 -7200 # Node ID 4d2d36f849415e17428408d92558d795086ce118 # Parent e82caf5f5a8a4b887308e0b3272c81bc1ab4379f Removed the square function, made saturation/desaturation options float-based. diff -r e82caf5f5a8a -r 4d2d36f84941 optimiser.py --- a/optimiser.py Fri Oct 09 14:20:02 2015 +0200 +++ b/optimiser.py Fri Oct 09 18:33:22 2015 +0200 @@ -2,7 +2,7 @@ """ Convert and optimise images for display in an Acorn Electron MODE 1 variant -with four colours per line but eight colours available for selection for each +with four colours per line but eight colours available for selection on each line. Copyright (C) 2015 Paul Boddie @@ -35,8 +35,6 @@ # Basic colour operations. -def extra(x): return x - def within(v, lower, upper): return min(max(v, lower), upper) @@ -54,9 +52,6 @@ def scale(rgb): return tuple(map(lambda x: x / 255.0, rgb)) -def square(srgb): - return tuple(map(lambda x: pow(x, 2), srgb)) - def invert(srgb): return tuple(map(lambda x: 1.0 - x, srgb)) @@ -69,7 +64,7 @@ # Get the colour with components scaled from 0 to 1, plus the inverted # component values. - rgb = extra(scale(rgb)) + rgb = scale(rgb) rgbi = invert(rgb) pairs = zip(rgbi, rgb) @@ -302,11 +297,10 @@ Options are... --s - Saturate the input image (can be repeated) --d - Desaturate the input image (can be repeated) +-s - Saturate the input image (can be followed by a float, default 1.0) +-d - Desaturate the input image (can be followed by a float, default 1.0) -D - Darken the input image (can be followed by a float, default 1.0) -B - Brighten the input image (can be followed by a float, default 1.0) --2 - Square/diminish the bright corner colour contributions (experimental) -r - Rotate the input image clockwise -p - Generate a separate preview image @@ -327,17 +321,11 @@ # Preprocessing options that can be repeated for extra effect. - saturate = options.count("-s") - desaturate = options.count("-d") + saturate = get_float(options, "-s") + desaturate = get_float(options, "-d") darken = get_float(options, "-D") brighten = get_float(options, "-B") - # Experimental colour distribution modification. - - use_square = "-2" in options - if use_square: - extra = square - # General output options. rotate = "-r" in options @@ -361,7 +349,7 @@ for x in range(0, width): rgb = im.getpixel((x, y)) if saturate or desaturate: - rgb = saturate_rgb(rgb, saturate and math.pow(0.5, saturate) or math.pow(2, desaturate)) + rgb = saturate_rgb(rgb, saturate and 0.5 / saturate or 2 * desaturate) if darken or brighten: rgb = amplify_rgb(rgb, brighten and 0.5 / brighten or 2 * darken) im.putpixel((x, y), rgb)