packages feed

JuicyPixels-extra 0.5.0 → 0.5.1

raw patch · 30 files changed

+95/−69 lines, 30 filesbinary-addedPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+## Juicy Pixels Extra 0.5.1++* `scaleBilinear` no longer hangs when the target width or height is 0.+  [Issue 24](https://github.com/mrkkrp/JuicyPixels-extra/issues/24).+ ## Juicy Pixels Extra 0.5.0  * Changed how edge pixels are calculated when scaling via bilinear
Codec/Picture/Extra.hs view
@@ -53,31 +53,34 @@   Image a ->   -- | Scaled image   Image a-scaleBilinear width height img@Image {..} = runST $ do-  mimg <- M.newMutableImage width height-  let sx, sy :: Float-      sx = fromIntegral imageWidth / fromIntegral width-      sy = fromIntegral imageHeight / fromIntegral height-      go x' y'-        | x' >= width = go 0 (y' + 1)-        | y' >= height = M.unsafeFreezeImage mimg-        | otherwise = do-          let xf = fromIntegral x' * sx-              yf = fromIntegral y' * sy-              x, y :: Int-              x = floor xf-              y = floor yf-              δx = xf - fromIntegral x-              δy = yf - fromIntegral y-              pixelAt' i j =-                pixelAt img (min (pred imageWidth) i) (min (pred imageHeight) j)-          writePixel mimg x' y' $-            mulp (pixelAt' x y) ((1 - δx) * (1 - δy))-              `addp` mulp (pixelAt' (x + 1) y) (δx * (1 - δy))-              `addp` mulp (pixelAt' x (y + 1)) ((1 - δx) * δy)-              `addp` mulp (pixelAt' (x + 1) (y + 1)) (δx * δy)-          go (x' + 1) y'-  go 0 0+scaleBilinear width height img@Image {..}+  | width <= 0 || height <= 0 =+    generateImage (error "scaleBilinear: absurd") (max 0 width) (max 0 height)+  | otherwise = runST $ do+    mimg <- M.newMutableImage width height+    let sx, sy :: Float+        sx = fromIntegral imageWidth / fromIntegral width+        sy = fromIntegral imageHeight / fromIntegral height+        go x' y'+          | x' >= width = go 0 (y' + 1)+          | y' >= height = M.unsafeFreezeImage mimg+          | otherwise = do+            let xf = fromIntegral x' * sx+                yf = fromIntegral y' * sy+                x, y :: Int+                x = floor xf+                y = floor yf+                δx = xf - fromIntegral x+                δy = yf - fromIntegral y+                pixelAt' i j =+                  pixelAt img (min (pred imageWidth) i) (min (pred imageHeight) j)+            writePixel mimg x' y' $+              mulp (pixelAt' x y) ((1 - δx) * (1 - δy))+                `addp` mulp (pixelAt' (x + 1) y) (δx * (1 - δy))+                `addp` mulp (pixelAt' x (y + 1)) ((1 - δx) * δy)+                `addp` mulp (pixelAt' (x + 1) (y + 1)) (δx * δy)+            go (x' + 1) y'+    go 0 0  #define scaleBilinear_spec(pixel) \ {-# SPECIALIZE scaleBilinear :: Int -> Int -> Image pixel -> Image pixel #-}
JuicyPixels-extra.cabal view
@@ -1,6 +1,6 @@ cabal-version:   1.18 name:            JuicyPixels-extra-version:         0.5.0+version:         0.5.1 license:         BSD3 license-file:    LICENSE.md maintainer:      Mark Karpov <markkarpov92@gmail.com>
bench/Main.hs view
@@ -9,49 +9,49 @@   defaultMain     [ bgroup         "scaleBilinear"-        [ baction "512 × 512" (scaleBilinear 512 512) "data-examples/lenna.png",-          baction "256 × 256" (scaleBilinear 256 256) "data-examples/lenna.png",-          baction "1024 × 1024" (scaleBilinear 1024 1024) "data-examples/lenna.png"+        [ baction "512 × 512" (scaleBilinear 512 512) "data-examples/macaque.png",+          baction "256 × 256" (scaleBilinear 256 256) "data-examples/macaque.png",+          baction "1024 × 1024" (scaleBilinear 1024 1024) "data-examples/macaque.png"         ],       bgroup         "crop"-        [ baction "on 256 horizontally" (crop 256 0 256 512) "data-examples/lenna.png",-          baction "on 265 vertically" (crop 0 256 512 256) "data-examples/lenna.png"+        [ baction "on 256 horizontally" (crop 256 0 256 512) "data-examples/macaque.png",+          baction "on 265 vertically" (crop 0 256 512 256) "data-examples/macaque.png"         ],       bgroup         "flipHorizontally"-        [ baction "512 × 512" flipHorizontally "data-examples/lenna.png",-          baction "100 × 100" flipHorizontally "data-examples/lenna-scaled-down.png"+        [ baction "512 × 512" flipHorizontally "data-examples/macaque.png",+          baction "100 × 100" flipHorizontally "data-examples/macaque-scaled-down.png"         ],       bgroup         "flipVertically"-        [ baction "512 × 512" flipVertically "data-examples/lenna.png",-          baction "100 × 100" flipVertically "data-examples/lenna-scaled-down.png"+        [ baction "512 × 512" flipVertically "data-examples/macaque.png",+          baction "100 × 100" flipVertically "data-examples/macaque-scaled-down.png"         ],       bgroup         "rotateLeft90"-        [ baction "512 × 512" rotateLeft90 "data-examples/lenna.png",-          baction "100 × 100" rotateLeft90 "data-examples/lenna-scaled-down.png"+        [ baction "512 × 512" rotateLeft90 "data-examples/macaque.png",+          baction "100 × 100" rotateLeft90 "data-examples/macaque-scaled-down.png"         ],       bgroup         "rotateRight90"-        [ baction "512 × 512" rotateRight90 "data-examples/lenna.png",-          baction "100 × 100" rotateRight90 "data-examples/lenna-scaled-down.png"+        [ baction "512 × 512" rotateRight90 "data-examples/macaque.png",+          baction "100 × 100" rotateRight90 "data-examples/macaque-scaled-down.png"         ],       bgroup         "rotate180"-        [ baction "512 × 512" rotate180 "data-examples/lenna.png",-          baction "100 × 100" rotate180 "data-examples/lenna-scaled-down.png"+        [ baction "512 × 512" rotate180 "data-examples/macaque.png",+          baction "100 × 100" rotate180 "data-examples/macaque-scaled-down.png"         ],       bgroup         "beside"-        [ baction "1024 × 512" beside' "data-examples/lenna.png",-          baction "200 × 100" beside' "data-examples/lenna-scaled-down.png"+        [ baction "1024 × 512" beside' "data-examples/macaque.png",+          baction "200 × 100" beside' "data-examples/macaque-scaled-down.png"         ],       bgroup         "below"-        [ baction "512 × 1024" below' "data-examples/lenna.png",-          baction "100 × 200" below' "data-examples/lenna-scaled-down.png"+        [ baction "512 × 1024" below' "data-examples/macaque.png",+          baction "100 × 200" below' "data-examples/macaque-scaled-down.png"         ]     ]   where
+ data-examples/empty.png view

binary file changed (absent → 65 bytes)

− data-examples/lenna-180-rotated.png

binary file changed (735114 → absent bytes)

− data-examples/lenna-below.png

binary file changed (1469523 → absent bytes)

− data-examples/lenna-beside.png

binary file changed (747724 → absent bytes)

− data-examples/lenna-cropped.png

binary file changed (62830 → absent bytes)

− data-examples/lenna-horizontal-flip.png

binary file changed (471314 → absent bytes)

− data-examples/lenna-left-rotated.png

binary file changed (708195 → absent bytes)

− data-examples/lenna-right-rotated.png

binary file changed (466243 → absent bytes)

− data-examples/lenna-scaled-down.png

binary file changed (29045 → absent bytes)

− data-examples/lenna-scaled-up.png

binary file changed (985068 → absent bytes)

− data-examples/lenna-vertical-flip.png

binary file changed (471109 → absent bytes)

− data-examples/lenna.png

binary file changed (473831 → absent bytes)

+ data-examples/macaque-180-rotated.png view

binary file changed (absent → 560827 bytes)

+ data-examples/macaque-below.png view

binary file changed (absent → 1121878 bytes)

+ data-examples/macaque-beside.png view

binary file changed (absent → 578319 bytes)

+ data-examples/macaque-cropped.png view

binary file changed (absent → 85981 bytes)

+ data-examples/macaque-height-1.png view

binary file changed (absent → 850 bytes)

+ data-examples/macaque-horizontal-flip.png view

binary file changed (absent → 560957 bytes)

+ data-examples/macaque-left-rotated.png view

binary file changed (absent → 548154 bytes)

+ data-examples/macaque-right-rotated.png view

binary file changed (absent → 547650 bytes)

+ data-examples/macaque-scaled-down.png view

binary file changed (absent → 25771 bytes)

+ data-examples/macaque-scaled-up.png view

binary file changed (absent → 789246 bytes)

+ data-examples/macaque-vertical-flip.png view

binary file changed (absent → 560425 bytes)

+ data-examples/macaque-width-1.png view

binary file changed (absent → 1272 bytes)

+ data-examples/macaque.png view

binary file changed (absent → 560849 bytes)

tests/Codec/Picture/ExtraSpec.hs view
@@ -31,20 +31,38 @@     it "produces the same image" $       checkWithFiles         (scaleBilinear 512 512)-        "data-examples/lenna.png"-        "data-examples/lenna.png"+        "data-examples/macaque.png"+        "data-examples/macaque.png"   context "when we scale down" $     it "produces correct image" $       checkWithFiles         (scaleBilinear 100 100)-        "data-examples/lenna.png"-        "data-examples/lenna-scaled-down.png"+        "data-examples/macaque.png"+        "data-examples/macaque-scaled-down.png"   context "when we scale up" $     it "produces correct image" $       checkWithFiles         (scaleBilinear 600 600)-        "data-examples/lenna.png"-        "data-examples/lenna-scaled-up.png"+        "data-examples/macaque.png"+        "data-examples/macaque-scaled-up.png"+  context "when we scale to 1 width" $+    it "produces correct image" $+      checkWithFiles+        (scaleBilinear 1 512)+        "data-examples/macaque.png"+        "data-examples/macaque-width-1.png"+  context "when we scale to 1 height" $+    it "produces correct image" $+      checkWithFiles+        (scaleBilinear 512 1)+        "data-examples/macaque.png"+        "data-examples/macaque-height-1.png"+  context "when we scale to 0x0" $+    it "produces the empty image" $+      checkWithFiles+        (scaleBilinear 0 0)+        "data-examples/macaque.png"+        "data-examples/empty.png"  cropSpec :: Spec cropSpec = do@@ -52,14 +70,14 @@     it "produces correct image" $       checkWithFiles         (crop 211 210 178 191)-        "data-examples/lenna.png"-        "data-examples/lenna-cropped.png"+        "data-examples/macaque.png"+        "data-examples/macaque-cropped.png"   context "when we pass arguments within image size (vertical)" $     it "produces correct image" $       checkWithFiles         (crop 0 512 512 512)-        "data-examples/lenna-below.png"-        "data-examples/lenna.png"+        "data-examples/macaque-below.png"+        "data-examples/macaque.png"  flipHorizontallySpec :: Spec flipHorizontallySpec =@@ -67,8 +85,8 @@     it "produces correct image" $       checkWithFiles         flipHorizontally-        "data-examples/lenna.png"-        "data-examples/lenna-horizontal-flip.png"+        "data-examples/macaque.png"+        "data-examples/macaque-horizontal-flip.png"  flipVerticallySpec :: Spec flipVerticallySpec =@@ -76,8 +94,8 @@     it "produces correct image" $       checkWithFiles         flipVertically-        "data-examples/lenna.png"-        "data-examples/lenna-vertical-flip.png"+        "data-examples/macaque.png"+        "data-examples/macaque-vertical-flip.png"  rotateLeft90Spec :: Spec rotateLeft90Spec =@@ -85,8 +103,8 @@     it "produces correct image" $       checkWithFiles         rotateLeft90-        "data-examples/lenna.png"-        "data-examples/lenna-left-rotated.png"+        "data-examples/macaque.png"+        "data-examples/macaque-left-rotated.png"  rotateRight90Spec :: Spec rotateRight90Spec =@@ -94,8 +112,8 @@     it "produces correct image" $       checkWithFiles         rotateRight90-        "data-examples/lenna.png"-        "data-examples/lenna-right-rotated.png"+        "data-examples/macaque.png"+        "data-examples/macaque-right-rotated.png"  rotate180Spec :: Spec rotate180Spec =@@ -103,8 +121,8 @@     it "produces correct image" $       checkWithFiles         rotate180-        "data-examples/lenna.png"-        "data-examples/lenna-180-rotated.png"+        "data-examples/macaque.png"+        "data-examples/macaque-180-rotated.png"  besideSpec :: Spec besideSpec =@@ -112,8 +130,8 @@     it "produces correct image" $       checkWithFiles         (\x -> beside [x, x])-        "data-examples/lenna.png"-        "data-examples/lenna-beside.png"+        "data-examples/macaque.png"+        "data-examples/macaque-beside.png"  belowSpec :: Spec belowSpec =@@ -121,8 +139,8 @@     it "produces correct image" $       checkWithFiles         (\x -> below [x, x])-        "data-examples/lenna.png"-        "data-examples/lenna-below.png"+        "data-examples/macaque.png"+        "data-examples/macaque-below.png"  -- | Run a transforming on the image loaded from a file and compare the -- resulting image with the contents of another file.