# HG changeset patch # User Paul Boddie # Date 1444481920 -7200 # Node ID 9c39e4cb3ecdc0a404617cd5c8ef6d1a9e3c2972 # Parent 429cc2ef9b9f6025b616be866f5b145a1c07e556# Parent b147df07482fe86e9479a8979ba3e17de41fb577 Merged channel operation performance improvements. diff -r 429cc2ef9b9f -r 9c39e4cb3ecd optimiser.py --- a/optimiser.py Sat Oct 10 14:41:25 2015 +0200 +++ b/optimiser.py Sat Oct 10 14:58:40 2015 +0200 @@ -47,13 +47,16 @@ return math.sqrt(pow(r1 - r2, 2) + pow(g1 - g2, 2) + pow(b1 - b2, 2)) def restore(srgb): - return tuple(map(lambda x: int(x * 255.0), srgb)) + r, g, b = srgb + return int(r * 255.0), int(g * 255.0), int(b * 255.0) def scale(rgb): - return tuple(map(lambda x: x / 255.0, rgb)) + r, g, b = rgb + return r / 255.0, g / 255.0, b / 255.0 def invert(srgb): - return tuple(map(lambda x: 1.0 - x, srgb)) + r, g, b = srgb + return 1.0 - r, 1.0 - g, 1.0 - b # Colour distribution functions. @@ -158,13 +161,15 @@ return x >= 0 and 1 or -1 def saturate_rgb(rgb, exp): - return tuple([saturate_value(x, exp) for x in rgb]) + r, g, b = rgb + return saturate_value(r, exp), saturate_value(g, exp), saturate_value(b, exp) def saturate_value(x, exp): return int(127.5 + sign(x - 127.5) * 127.5 * pow(abs(x - 127.5) / 127.5, exp)) def amplify_rgb(rgb, exp): - return tuple([amplify_value(x, exp) for x in rgb]) + r, g, b = rgb + return amplify_value(r, exp), amplify_value(g, exp), amplify_value(b, exp) def amplify_value(x, exp): return int(pow(x / 255.0, exp) * 255.0) @@ -341,12 +346,20 @@ if x < width - 1: rgbn = im.getpixel((x+1, y)) - rgbn = tuple(map(lambda i: clip(i[0] + (i[1] - i[2]) / 4.0), zip(rgbn, rgb, value))) + rgbn = ( + clip(rgbn[0] + (rgb[0] - value[0]) / 4.0), + clip(rgbn[1] + (rgb[1] - value[1]) / 4.0), + clip(rgbn[2] + (rgb[2] - value[2]) / 4.0) + ) im.putpixel((x+1, y), rgbn) if y < height - 1: rgbn = im.getpixel((x, y+1)) - rgbn = tuple(map(lambda i: clip(i[0] + (i[1] - i[2]) / 2.0), zip(rgbn, rgb, value))) + rgbn = ( + clip(rgbn[0] + (rgb[0] - value[0]) / 2.0), + clip(rgbn[1] + (rgb[1] - value[1]) / 2.0), + clip(rgbn[2] + (rgb[2] - value[2]) / 2.0) + ) im.putpixel((x, y+1), rgbn) pim.putdata(im.getdata())