packages feed

JuicyPixels 3.2.6.3 → 3.2.6.4

raw patch · 3 files changed

+34/−20 lines, 3 filesdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

- Codec.Picture: generateImage :: (Pixel a) => (Int -> Int -> a) -> Int -> Int -> Image a
+ Codec.Picture: generateImage :: (Pixel px) => (Int -> Int -> px) -> Int -> Int -> Image px
- Codec.Picture.Types: generateImage :: (Pixel a) => (Int -> Int -> a) -> Int -> Int -> Image a
+ Codec.Picture.Types: generateImage :: (Pixel px) => (Int -> Int -> px) -> Int -> Int -> Image px

Files

JuicyPixels.cabal view
@@ -1,5 +1,5 @@ Name:                JuicyPixels-Version:             3.2.6.3+Version:             3.2.6.4 Synopsis:            Picture loading/serialization (in png, jpeg, bitmap, gif, tga, tiff and radiance) Description:     <<data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMAAAADABAMAAACg8nE0AAAAElBMVEUAAABJqDSTWEL/qyb///8AAABH/1GTAAAAAXRSTlMAQObYZgAAAN5JREFUeF7s1sEJgFAQxFBbsAV72v5bEVYWPwT/XDxmCsi7zvHXavYREBDI3XP2GgICqBBYuwIC+/rVayPUAyAg0HvIXBcQoDFDGnUBgWQQ2Bx3AYFaRoBpAQHWb3bt2ARgGAiCYFFuwf3X5HA/McgGJWI2FdykCv4aBYzmKwDwvl6NVmUAAK2vlwEALK7fo88GANB6HQsAAAAAAAAA7P94AQCzswEAAAAAAAAAAAAAAAAAAICzh4UAO4zWAYBfRutHA4Bn5C69JhowAMGoBaMWDG0wCkbBKBgFo2AUAACPmegUST/IJAAAAABJRU5ErkJggg==>>@@ -28,7 +28,7 @@ Source-Repository this     Type:      git     Location:  git://github.com/Twinside/Juicy.Pixels.git-    Tag:       v3.2.6.3+    Tag:       v3.2.6.4  Flag Mmap     Description: Enable the file loading via mmap (memory map)
changelog view
@@ -1,6 +1,10 @@ Change log ========== +v3.2.6.3 December 2015+----------------------+ * Fix: previous broken bugfix.+ v3.2.6.3 November 2015 ----------------------  * Fix: Fixing unwanted sharing with createMutableImage due to
src/Codec/Picture/Types.hs view
@@ -309,6 +309,7 @@ -- The source image shouldn't be used after this operation.
 unsafeThawImage :: (Storable (PixelBaseComponent px), PrimMonad m)
                 => Image px -> m (MutableImage (PrimState m) px)
+{-# NOINLINE unsafeThawImage #-}
 unsafeThawImage (Image w h d) = MutableImage w h `liftM` V.unsafeThaw d
 
 -- | `O(1)` Unsafe convert a mutable image to an immutable one without copying.
@@ -323,9 +324,8 @@                    -> Int -- ^ Height
                    -> px  -- ^ Background color
                    -> m (MutableImage (PrimState m) px)
-{-# NOINLINE createMutableImage #-}
 createMutableImage width height background =
-   unsafeThawImage $ generateImage (\_ _ -> background) width height
+   generateMutableImage (\_ _ -> background) width height
 
 -- | Create a mutable image with garbage as content. All data
 -- is uninitialized.
@@ -733,6 +733,26 @@     convertImage :: Image a -> Image b
     convertImage = pixelMap convertPixel
 
+generateMutableImage :: forall m px. (Pixel px, PrimMonad m)
+                     => (Int -> Int -> px)  -- ^ Generating function, with `x` and `y` params.
+                     -> Int        -- ^ Width in pixels
+                     -> Int        -- ^ Height in pixels
+                     -> m (MutableImage (PrimState m) px)
+{-# INLINE generateMutableImage #-}
+generateMutableImage f w h = MutableImage w h <$> generated where
+  compCount = componentCount (undefined :: px)
+
+  generated = do
+    arr <- M.new (w * h * compCount)
+    let lineGenerator _ !y | y >= h = return ()
+        lineGenerator !lineIdx y = column lineIdx 0
+          where column !idx !x | x >= w = lineGenerator idx $ y + 1
+                column idx x = do
+                    unsafeWritePixel arr idx $ f x y
+                    column (idx + compCount) $ x + 1
+    lineGenerator 0 0
+    return arr
+
 -- | Create an image given a function to generate pixels.
 -- The function will receive values from 0 to width-1 for the x parameter
 -- and 0 to height-1 for the y parameter. The coordinates 0,0 are the upper
@@ -744,25 +764,15 @@ -- > imageCreator path = writePng path $ generateImage pixelRenderer 250 300
 -- >    where pixelRenderer x y = PixelRGB8 (fromIntegral x) (fromIntegral y) 128
 --
-generateImage :: forall a. (Pixel a)
-              => (Int -> Int -> a)  -- ^ Generating function, with `x` and `y` params.
+generateImage :: forall px. (Pixel px)
+              => (Int -> Int -> px)  -- ^ Generating function, with `x` and `y` params.
               -> Int        -- ^ Width in pixels
               -> Int        -- ^ Height in pixels
-              -> Image a
+              -> Image px
 {-# INLINE generateImage #-}
-generateImage f w h = Image { imageWidth = w, imageHeight = h, imageData = generated }
-  where compCount = componentCount (undefined :: a)
-        generated = runST $ do
-            arr <- M.new (w * h * compCount)
-            let lineGenerator _ !y | y >= h = return ()
-                lineGenerator !lineIdx y = column lineIdx 0
-                  where column !idx !x | x >= w = lineGenerator idx $ y + 1
-                        column idx x = do
-                            unsafeWritePixel arr idx $ f x y
-                            column (idx + compCount) $ x + 1
-
-            lineGenerator 0 0
-            V.unsafeFreeze arr
+generateImage f w h = runST img where
+  img :: ST s (Image px)
+  img = generateMutableImage f w h >>= unsafeFreezeImage
 
 -- | Create an image using a monadic initializer function.
 -- The function will receive values from 0 to width-1 for the x parameter