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 +5/−0
- Codec/Picture/Extra.hs +28/−25
- JuicyPixels-extra.cabal +1/−1
- bench/Main.hs +19/−19
- data-examples/empty.png binary
- data-examples/lenna-180-rotated.png binary
- data-examples/lenna-below.png binary
- data-examples/lenna-beside.png binary
- data-examples/lenna-cropped.png binary
- data-examples/lenna-horizontal-flip.png binary
- data-examples/lenna-left-rotated.png binary
- data-examples/lenna-right-rotated.png binary
- data-examples/lenna-scaled-down.png binary
- data-examples/lenna-scaled-up.png binary
- data-examples/lenna-vertical-flip.png binary
- data-examples/lenna.png binary
- data-examples/macaque-180-rotated.png binary
- data-examples/macaque-below.png binary
- data-examples/macaque-beside.png binary
- data-examples/macaque-cropped.png binary
- data-examples/macaque-height-1.png binary
- data-examples/macaque-horizontal-flip.png binary
- data-examples/macaque-left-rotated.png binary
- data-examples/macaque-right-rotated.png binary
- data-examples/macaque-scaled-down.png binary
- data-examples/macaque-scaled-up.png binary
- data-examples/macaque-vertical-flip.png binary
- data-examples/macaque-width-1.png binary
- data-examples/macaque.png binary
- tests/Codec/Picture/ExtraSpec.hs +42/−24
@@ -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
@@ -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 #-}
@@ -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>
@@ -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
binary file changed (absent → 65 bytes)
binary file changed (735114 → absent bytes)
binary file changed (1469523 → absent bytes)
binary file changed (747724 → absent bytes)
binary file changed (62830 → absent bytes)
binary file changed (471314 → absent bytes)
binary file changed (708195 → absent bytes)
binary file changed (466243 → absent bytes)
binary file changed (29045 → absent bytes)
binary file changed (985068 → absent bytes)
binary file changed (471109 → absent bytes)
binary file changed (473831 → absent bytes)
binary file changed (absent → 560827 bytes)
binary file changed (absent → 1121878 bytes)
binary file changed (absent → 578319 bytes)
binary file changed (absent → 85981 bytes)
binary file changed (absent → 850 bytes)
binary file changed (absent → 560957 bytes)
binary file changed (absent → 548154 bytes)
binary file changed (absent → 547650 bytes)
binary file changed (absent → 25771 bytes)
binary file changed (absent → 789246 bytes)
binary file changed (absent → 560425 bytes)
binary file changed (absent → 1272 bytes)
binary file changed (absent → 560849 bytes)
@@ -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.