Fastest way to iterate pixels in a canvas and copy some of them in another one
I'm into a 2D/3D graphic project and I'm facing a performance problem. My algorithm takes two images: a picture and the relative grayscale depth map. I have also an array of 10 canvases ("layers") initally blank. A note: all the images have the same dimension. I need to check every pixel X;Y of the depth map and, depending on its color value, access one of the 10 canvases and draw the X;Y pixel of the original image on it. Resulting algorithm is someting like: for (var y = 0; y < totalHeight; ++y) { for (var x = 0; x < totalWidth; ++x) { var index = (y * totalWidth + x) * 4; // index of the