packages feed

JuicyPixels-extra 0.1.1 → 0.2.0

raw patch · 10 files changed

+139/−11 lines, 10 filesdep ~JuicyPixels-extrabinary-addedPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: JuicyPixels-extra

API changes (from Hackage documentation)

+ Codec.Picture.Extra: below :: Pixel a => [Image a] -> Image a
+ Codec.Picture.Extra: beside :: Pixel a => [Image a] -> Image a
+ Codec.Picture.Extra: rotate180 :: Pixel a => Image a -> Image a

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+## Juicy Pixels Extra 0.2.0++* Added `rotate180`, `beside`, and `below`.+ ## Juicy Pixels Extra 0.1.1  * Added benchmarks.
Codec/Picture/Extra.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Codec.Picture.Extra--- Copyright   :  © 2016 Mark Karpov+-- Copyright   :  © 2016–2017 Mark Karpov -- License     :  BSD 3 clause -- -- Maintainer  :  Mark Karpov <markkarpov@openmailbox.org>@@ -20,12 +20,16 @@   , flipHorizontally   , flipVertically   , rotateLeft90-  , rotateRight90 )+  , rotateRight90+  , rotate180+  , beside+  , below ) where  import Codec.Picture import Control.Monad.ST import qualified Codec.Picture.Types as M+import Data.List (foldl1')  -- | Scale image using bi-linear interpolation. This is specialized to -- 'PixelRGB8' only for speed (polymorphic version is easily written, but@@ -130,3 +134,49 @@   where     gen x y = pixelAt img y (imageHeight - 1 - x) {-# INLINEABLE rotateRight90 #-}++-- | Rotate image by 180°, i.e flip both vertically and horizontally.+--+-- @since 0.2.0++rotate180 :: Pixel a => Image a -> Image a+rotate180 img@(Image w h _) = generateImage g w h+  where+    g x y = pixelAt img (w - 1 - x) (h - 1 - y)+{-# INLINEABLE rotate180 #-}++-- | Create an image by placing several images side by side. If the images+-- are of differnet heights the smallest height is used.+--+-- @since 0.2.0++beside :: Pixel a => [Image a] -> Image a+beside = foldl1' go+  where+    go :: Pixel a => Image a -> Image a -> Image a+    go img1@(Image w1 h1 _) img2@(Image w2 h2 _) =+      generateImage g (w1 + w2) h+      where+        g x+          | x < w1 = pixelAt img1 x+          | otherwise = pixelAt img2 (x - w1)+        h = min h1 h2+{-# INLINEABLE beside #-}++-- | Create an image by placing several images in a vertical stack. If the+-- images are of differnet widths the smallest width is used.+--+-- @since 0.2.0++below :: Pixel a => [Image a] -> Image a+below = foldl1' go+  where+    go :: Pixel a => Image a -> Image a -> Image a+    go img1@(Image w1 h1 _) img2@(Image w2 h2 _) =+      generateImage g w (h1 + h2)+      where+        g x y+          | y < h1 = pixelAt img1 x y+          | otherwise = pixelAt img2 x (y - h1)+        w = min w1 w2+{-# INLINEABLE below #-}
JuicyPixels-extra.cabal view
@@ -1,7 +1,7 @@ -- -- Cabal configuration for ‘JuicyPixels-extra’ package. ----- Copyright © 2016 Mark Karpov <markkarpov@openmailbox.org>+-- Copyright © 2016–2017 Mark Karpov <markkarpov@openmailbox.org> -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are@@ -31,8 +31,9 @@ -- POSSIBILITY OF SUCH DAMAGE.  name:                 JuicyPixels-extra-version:              0.1.1+version:              0.2.0 cabal-version:        >= 1.10+tested-with:          GHC==7.8.4, GHC==7.10.3, GHC==8.0.2 license:              BSD3 license-file:         LICENSE.md author:               Mark Karpov <markkarpov@openmailbox.org>@@ -72,7 +73,7 @@   type:               exitcode-stdio-1.0   build-depends:      base              >= 4.7 && < 5                     , JuicyPixels       >= 3.2.6.4 && < 3.3-                    , JuicyPixels-extra >= 0.1.1+                    , JuicyPixels-extra                     , hspec             >= 2.0   other-modules:      Codec.Picture.ExtraSpec   if flag(dev)@@ -87,10 +88,10 @@   type:               exitcode-stdio-1.0   build-depends:      base              >= 4.7 && < 5.0                     , JuicyPixels       >= 3.2.6.4 && < 3.3-                    , JuicyPixels-extra >= 0.1.1+                    , JuicyPixels-extra                     , criterion         >= 0.6.2.1 && < 1.2   if flag(dev)-    ghc-options:      -Wall -Werror+    ghc-options:      -O2 -Wall -Werror   else     ghc-options:      -O2 -Wall   default-language:   Haskell2010
LICENSE.md view
@@ -1,4 +1,4 @@-Copyright © 2016 Mark Karpov+Copyright © 2016–2017 Mark Karpov  All rights reserved. 
README.md view
@@ -13,10 +13,12 @@  * scaling (bi-linear interpolation); * cropping;-* flipping horizontally and vertically and 90° rotation (left and right).+* flipping horizontally and vertically;+* 90° and 180° rotation (left and right);+* aligning several images side by side or one on top of the other.  ## License -Copyright © 2016 Mark Karpov+Copyright © 2016–2017 Mark Karpov  Distributed under BSD 3 clause license.
bench/Main.hs view
@@ -1,7 +1,7 @@ -- -- Benchmarks for the ‘JuicyPixels-extra’ package. ----- Copyright © 2016 Mark Karpov <markkarpov@openmailbox.org>+-- Copyright © 2016–2017 Mark Karpov <markkarpov@openmailbox.org> -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are@@ -58,7 +58,19 @@   , bgroup "rotateRight90"     [ baction "512 × 512" rotateRight90 "data-examples/lenna.png"     , baction "100 × 100" rotateRight90 "data-examples/lenna-scaled-down.png" ]+  , bgroup "rotate180"+    [ baction "512 × 512" rotate180 "data-examples/lenna.png"+    , baction "100 × 100" rotate180 "data-examples/lenna-scaled-down.png" ]+  , bgroup "beside"+    [ baction "1024 × 512" beside' "data-examples/lenna.png"+    , baction "200 × 100"  beside' "data-examples/lenna-scaled-down.png" ]+  , bgroup "below"+    [ baction "512 × 1024" below' "data-examples/lenna.png"+    , baction "100 × 200"  below' "data-examples/lenna-scaled-down.png" ]   ]+  where+    beside' img = beside [img, img]+    below'  img = below  [img, img]  -- | Run a benchmark given function to benchmark and where to get image to -- pass as an input.
+ data-examples/lenna-180-rotated.png view

binary file changed (absent → 735114 bytes)

+ data-examples/lenna-below.png view

binary file changed (absent → 1469523 bytes)

+ data-examples/lenna-beside.png view

binary file changed (absent → 747724 bytes)

tests/Codec/Picture/ExtraSpec.hs view
@@ -1,3 +1,35 @@+--+-- Tests for the ‘JuicyPixels-extra’ package.+--+-- Copyright © 2016–2017 Mark Karpov <markkarpov@openmailbox.org>+--+-- Redistribution and use in source and binary forms, with or without+-- modification, are permitted provided that the following conditions are+-- met:+--+-- * Redistributions of source code must retain the above copyright notice,+--   this list of conditions and the following disclaimer.+--+-- * Redistributions in binary form must reproduce the above copyright+--   notice, this list of conditions and the following disclaimer in the+--   documentation and/or other materials provided with the distribution.+--+-- * Neither the name Mark Karpov nor the names of contributors may be used+--   to endorse or promote products derived from this software without+--   specific prior written permission.+--+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS “AS IS” AND ANY+-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+-- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY+-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+-- POSSIBILITY OF SUCH DAMAGE.+ module Codec.Picture.ExtraSpec   ( main   , spec )@@ -20,6 +52,9 @@   describe "flipVertically"    flipVerticallySpec   describe "rotateLeft90Spec"  rotateLeft90Spec   describe "rotateRight90Spec" rotateRight90Spec+  describe "rotate180"         rotate180Spec+  describe "beside"            besideSpec+  describe "below"             belowSpec  scaleBilinearSpec :: Spec scaleBilinearSpec = do@@ -78,6 +113,30 @@       checkWithFiles rotateRight90         "data-examples/lenna.png"         "data-examples/lenna-right-rotated.png"++rotate180Spec :: Spec+rotate180Spec =+  context "when we rotate by 180°" $+    it "produces correct image" $+      checkWithFiles rotate180+        "data-examples/lenna.png"+        "data-examples/lenna-180-rotated.png"++besideSpec :: Spec+besideSpec =+  context "when we place images beside each other" $+    it "produces correct image" $+      checkWithFiles (\x -> beside [x,x])+        "data-examples/lenna.png"+        "data-examples/lenna-beside.png"++belowSpec :: Spec+belowSpec =+  context "when we place images below each other" $+    it "produces correct image" $+      checkWithFiles (\x -> below [x,x])+        "data-examples/lenna.png"+        "data-examples/lenna-below.png"  -- | Run given transforming function on image loaded from one file and -- compare resulting image with contents of another file.