From 16e9c133142e5a4b3e02c12da5e47996d2d9e334 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Mon, 9 Jul 2012 17:09:15 +0200 Subject: [PATCH] store the whole image in an array This shoves 9 seconds off the 9 seconds (or so) for the pixel region write access, for a 1k x 1k image. Yeah! Downside is the memory consumption: 12M for this size. But RAM is cheap and time is expensive. --- conformal.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/conformal.py b/conformal.py index 2b3dcdd..7662d50 100755 --- a/conformal.py +++ b/conformal.py @@ -78,6 +78,8 @@ def conformal_core(width, height, code, constraint, xl, xr, yt, yb, grid, checkb compiled=compile(code, "compiled code", "exec", 0, 1) compiledconstraint=compile(constraint, "compiled constraint code", "exec", 0, 1) + dests = [ array("B", "\x00" * width*height*bpp) for i in range(3) ] + for row in range(0, height): args = [] mods = [] @@ -124,21 +126,20 @@ def conformal_core(width, height, code, constraint, xl, xr, yt, yb, grid, checkb sqrs.extend( (bpp-1)*[ 255*(sqr % 2) ,] + [255, ] ) samples = gimp.gradient_get_custom_samples(gradient, args) - top_p = array("B", [ int(255*samples[col][i]+0.5) for col in range(0, width) for i in range(bpp) ] ) + dests[0][row*width*bpp : (row+1)*width*bpp] = array("B", [ int(255*samples[col][i]+0.5) for col in range(0, width) for i in range(bpp) ] ) - dest_rgns[0][0:width, row] = top_p.tostring() - samples = gimp.gradient_get_custom_samples("Default", mods) - top_p = array("B", [ int(255*samples[col][i]+0.5) for col in range(0, width) for i in range(bpp) ] ) - dest_rgns[1][0:width, row] = top_p.tostring() + dests[1][row*width*bpp : (row+1)*width*bpp] = array("B", [ int(255*samples[col][i]+0.5) for col in range(0, width) for i in range(bpp) ] ) - top_p = array("B", sqrs ) - dest_rgns[2][0:width, row] = top_p.tostring() + dests[2][row*width*bpp : (row+1)*width*bpp]= array("B", sqrs ) progress = progress + width if filename is None: gimp.progress_update(float(progress) / max_progress) + for i in range(3): + dest_rgns[i][0:width, 0:height] = dests[i].tostring() + for drawable in drawables: drawable.flush() drawable.update(0,0,width,height) -- 2.11.4.GIT