I have found out that in our engines, SSFML and minisphere, this causes a considerable speedup to getPixel:
function SurfaceWrap(image, hold) {
this.surface = image.createSurface();
this.width = image.width;
this.height = image.height;
var pixels = [];
this.update = function() {
var w = this.width, h = this.height;
for (var x = 0; x < w; ++x) {
pixels[x] = [];
for (var y = 0; y < h; ++y) {
pixels[x][y] = this.surface.getPixel(x, y);
}
}
}
if (!hold) this.update();
this.getPixel = function(x, y) {
return pixels[Math.floor(x)][Math.floor(y)];
}
this.rotate = function(r, s) {
this.surface.rotate(r, s);
this.update();
}
//... other methods...
}
I think it has to do with the domain bounds, between script engine and native execution because even with native side pixel caching, engine based caching is faster to retrieve from. The only downside to the above is, notice the rotate, I have to call the update method each time to get a fresh list. But my code only rotated the image once. The speedup isn't huge, though. Testing on 500 static images, the engine used to halt entirely in our engines. With this addition there is no visible halting, everything is just slow, like 10-17fps slow, but consistent which says this is much faster. Though in practice it may be slower, especially if you modify the surface a lot with rotations and other methods (I only wrapped the rotate method).
In Sphere1.5 the above errors with an out of memory error, after about 40 entities.