Move the loop that sets the pixels from Java to a JS native. Fixes #315.