Twinside/Juicy.Pixels — pull request #6 by dagit (2012-01-15 23:12:25+00:00)
Title: Refactored JuicyPixels to use Data.Vector

Hello,

I really like your Juicy Pixels library. I would like to use it for games and visualizations in OpenGL. Please allow me to justify why I refactored your code to use Data.Vector:

* OpenGL expects `Ptr a` for the data it accepts. The standard Haskell Arrays cannot support this without copying the image data elsewhere, which is O(ImageSize) of course.
* Data.Vector is often faster than the normal Arrays due to clever implementation tricks.
* Data.Vector is easier to use with Repa, which would then allow your users to do data parallel computations quite easily on their images.

I have not removed all uses of Arrays from your code. I simply started at the base types that you define and I converted things to `Data.Vector.Storable` and `Data.Vector.Storable.Mutable` as needed until I could compile and run the tests. I've tried to clean up warnings but it's possible I missed some as my GHC is spewing out lots of SpecConstr messages. More work could be done in the future to remove all uses of Array, but I didn't see that as important.

I ran the test suite and as far as I could tell I did not break anything. I have included a fix for issue #5. I also had to add primitive and vector as dependencies. Primitive is a dependency of vector and I needed it to give types to some of the functions. You might want to check the ranges I specified in the cabal file. I have only tested on Windows but I have no reason to believe that I broke anything on other platforms.

I have used `unsafeFreeze` in quite a few places, but I believe those uses to be safe. The `unsafe` part just means that you should not continue to mutate the data via an existing handle. I'm just trying to reduce copying the data, so if any use of `unsafeFreeze` looks unsafe please replace it with `freeze`.

Thank you for releasing JuicyPixels!

Jason