i think you are taking the wrong approach.
this page shows a fast redeye removal example http://disruptive-innovations.com/zoo/demos/eyes.html
instead of operating on the canvas data, you should operate on the imageData object, which is like a buffer and will not cause an invalidation paint event.
original function
structs.grid_canvas = function(size) {
var canvas = document.createElement("canvas");
canvas.width = size[0];
canvas.height = size[1];
var ctx = canvas.getContext("2d");
return {
set: function(pos, value) {
ctx.fillStyle = 'rgb(' + value +',0,0)';
ctx.fillRect(pos[0], pos[1], 2, 2);
},
get: function(pos) {
return ctx.getImageData(pos[0], pos[1], 1, 1).data[0];
}
}
}
new function structs.grid_imagedata = function(size) {
var canvas = document.createElement("canvas");
canvas.width = size[0];
canvas.height = size[1];
var ctx = canvas.getContext("2d");
var imgd = ctx.getImageData(0, 0, size[0], size[1]);
/**
//use this to invalidate the canvas at a reasonable frame_rate
var frame_rate = 24; //fps
var paint_frame = setInterval( function(){
ctx.putImageData(imgd, 0, 0);
}, 1000/frame_rate );
*/
return {
set: function(pos, value) {
var offset = (pos[1] * imgd.width + pos[0]) * 4;
// + 0=red, 1=green,2=blue,3=alpha
imgd.data[offset + 0]= value;
},
get: function(pos) {
var offset = (pos[1] * imgd.width + pos[0]) * 4;
// + 0=red, 1=green,2=blue,3=alpha
return imgd.data[offset + 0];
}
}
}