packages feed

picedit 0.2.0.0 → 0.2.1.0

raw patch · 3 files changed

+38/−5 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Picture: resize :: (Int, Int) -> Picture -> Picture
+ Data.Picture: scale :: Double -> Picture -> Picture

Files

app/Main.hs view
@@ -2,6 +2,7 @@   import Data.Picture   import System.Environment   import Data.Either+  import Numeric.LinearAlgebra (rows, cols)    data Options = Options { file :: FilePath                          , output :: FilePath@@ -13,6 +14,7 @@                          , argGamma :: Int                          , argBrightness :: Double                          , argCompress :: Int+                         , argScale :: Double                          }    opts = Options { file = ""@@ -25,6 +27,7 @@                  , argGamma = 1                  , argBrightness = 0                  , argCompress = 0+                 , argScale = 1                  }    main :: IO ()@@ -42,6 +45,7 @@         putStrLn "  --rotate <n> - rotate image by n degrees"         putStrLn "  --grayscale - turn the image grayscale"         putStrLn "  --invert - invert (negative) the image"+        putStrLn "  --scale <n> - scale the image using nearest-neighbor interpolation"         putStrLn "  --compress <n> - approximate the (width - n)-th rank of image using SVD, note: this is not size compression, a number between 0 (no compression) and image width (full compression)"         putStrLn "  --output <filename> - output name, defaults to output.png"       else do @@ -60,6 +64,7 @@                        . brightness (argBrightness options)                        . conditionalFn grayscale (argGrayscale options)                         . conditionalFn invert (argInvert options)+                       . scale (argScale options)                        . compress (argCompress options) $ p             writePicturePng (output options) edited             @@ -79,6 +84,7 @@   parseArgs ("--brightness":n:rest) opts = parseArgs rest (opts { argBrightness = read n })   parseArgs ("--gamma":n:rest) opts = parseArgs rest (opts { argGamma = read n })   parseArgs ("--compress":n:rest) opts = parseArgs rest (opts { argCompress = read n })+  parseArgs ("--scale":n:rest) opts = parseArgs rest (opts { argScale = read n })   parseArgs ("--output":n:rest) opts = parseArgs rest (opts { output = n })   parseArgs (name:rest) opts = parseArgs rest (opts { file = name }) 
picedit.cabal view
@@ -1,5 +1,5 @@ name:                picedit-version:             0.2.0.0+version:             0.2.1.0 synopsis:            simple image manipulation functions description:         Simple set of functions for image manipulation: contrast, brightnesss, rotation, etc. homepage:            https://github.com/mdibaiee/picedit#readme@@ -16,10 +16,10 @@ library   hs-source-dirs:      src   exposed-modules:     Data.Picture-  build-depends:       base >= 4.7 && < 5,-                       JuicyPixels >= 3.2.8 && < 3.3,-                       hmatrix >= 0.17.0.2 && < 0.19,-                       vector >= 0.11.0.0 && < 0.13+  build-depends:       base >= 4.7 && < 5+                     , JuicyPixels >= 3.2.8 && < 3.3+                     , hmatrix >= 0.17.0.2 && < 0.19+                     , vector >= 0.11.0.0 && < 0.13   default-language:    Haskell2010  executable picedit@@ -29,6 +29,7 @@   build-depends:       base                      , picedit                      , cli >= 0.1.2 && < 0.2+                     , hmatrix >= 0.17.0.2 && < 0.19   default-language:    Haskell2010  source-repository head
src/Data/Picture.hs view
@@ -22,6 +22,8 @@                     , invert                     , compress                     , embed+                    , resize+                    , Data.Picture.scale                     -- * Converting between Image and Picture                     , fromImage                     , toImage@@ -169,6 +171,30 @@          f b lm = (b * (cmap (1-) scaledAlpha)) + (lm * scaledAlpha)         maxAlpha = (rows ba><cols ba) $ zipWith max (toList . flatten $ ba) (toList . flatten . fit $ la)++    -- | Resize an image using nearest-neighbor interpolation+    resize :: (Int, Int) -> Picture -> Picture+    resize (sWidth, sHeight) (r, g, b, a) = (f r, f g, f b, f a)+      where+        initial = vector [0..fromIntegral sWidth * fromIntegral sHeight - 1]+        (width, height) = (rows r, cols r)+        factor = 2 ^ 16+        (xRatio, yRatio) = (width * factor `div` sWidth + 1, height * factor `div` sHeight + 1)+        f m = tr $ reshape sWidth $ V.map replace initial+          where+            v = flatten (tr m)+            replace index =+              let (x, y) = (floor index `mod` sWidth, floor index `div` sWidth)+                  (px, py) = (x * xRatio `div` factor, y * yRatio `div` factor)+              in v ! (py * width + px)++    -- | Scale an image using the resize function+    scale :: Double -> Picture -> Picture+    scale 1 p = p+    scale s (r, g, b, a) = resize (floor $ s * width, floor $ s * height) (r, g, b, a)+      where+        (width, height) = (fromIntegral $ rows r, fromIntegral $ cols r)+      bound (l, u) x = max l $ min u x     pixelBound = bound (0, 255)