Refactored JuicyPixels to use Data.Vector #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.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
andData.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. Theunsafe
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 ofunsafeFreeze
looks unsafe please replace it withfreeze
.Thank you for releasing JuicyPixels!
Jason