jgranick/NME — pull request #9 by djcsdy (2012-07-27 19:15:51+00:00)
Title: Implement BitmapData.noise() in neash and jeash

This implements `BitmapData.noise()` in neash and jeash.

I’ve reverse-engineered the behaviour of this function in Flash so, given the same parameters, these implementations should generate noise that is byte-for-byte identical to noise generated in Flash.

Note, however, that for noise that is generated with an alpha channel, there may be some rounding errors between platforms when retrieving the RGB channels due to some platforms storing bitmap data alpha pre-multiplied. For noise without an alpha channel, the RGB colour values should be identical between platforms. The values of the alpha channel itself should always be identical between platforms.

The jeash implementation is somewhat slow because the PRNG has to be implemented in JS in order to get identical behaviour to Flash. It should be possible to get a significant speedup by using JavaScript Typed Arrays where available, but I haven’t implemented that for now.

I’m not absolutely confident that I’ve got things exactly right in jeash with regard to `jeashLocked`. It seems to work in all cases, but a review of my code would be appreciated.

Also, note that I added a new private class `MinstdGenerator` to `jeash.BitmapData`. It implements the PRNG that is used to generate noise; I wasn’t sure where else to put it.

There are some test cases that prove that behaviour is identical between platforms here: https://github.com/djcsdy/reverse-noise. You can also follow through the history of that project to see how I went about reverse-engineering Flash (educated guesswork, mostly ;)). I wasn’t sure whether I should merge those test cases into NME. If you want me to do so, let me know.

In the future I intend to implement `BitmapData.perlinNoise()` as well.