From d355b1fe97c330be3bbc7616b51e5a162c09d110 Mon Sep 17 00:00:00 2001 From: ippo615 Date: Sun, 4 Aug 2013 14:34:56 -0400 Subject: [PATCH] Improved performance of convolution filters. Previously, I would work with a regular array and compute/store/copy to/from that array. It should be faster to create an imageData object, create the convolution result in that object and finally: `context.putImageData(result)`. --- src/filters/ConvolvePack.js | 48 ++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/filters/ConvolvePack.js b/src/filters/ConvolvePack.js index bf522041..5d8e7ef6 100644 --- a/src/filters/ConvolvePack.js +++ b/src/filters/ConvolvePack.js @@ -1,6 +1,6 @@ (function() { - var convolve_internal = function(imageData,matrix){ + var convolve_internal = function(imageData,matrix,result){ // Input data var pixels = imageData.data, imageSizeX = imageData.width, @@ -9,8 +9,9 @@ pixel; // An array for storing the result - var result = []; - result.length = imageSizeX*imageSizeY*4; + // (this should now be passed as the 3rd argument) + // var result = []; + // result.length = imageSizeX*imageSizeY*4; // Determine the size and demsionality of the matrix // Note: it should be square and odd (3,5,7,9 etc...) @@ -57,13 +58,14 @@ } // copy the result to the original canvas - var lastPos = nPixels*4; - for( pos=0; pos