brillo-juicy 0.2.4 → 0.3.0
raw patch · 3 files changed
+42/−21 lines, 3 filesdep +webpdep −bmpdep ~brillodep ~bytestring
Dependencies added: webp
Dependencies removed: bmp
Dependency ranges changed: brillo, bytestring
Files
- Brillo/Juicy.hs +26/−8
- brillo-juicy.cabal +14/−13
- brillo-juicy.hs +2/−0
Brillo/Juicy.hs view
@@ -14,6 +14,7 @@ loadJuicyWithMetadata, loadJuicyJPG, loadJuicyPNG,+ loadJuicyWebP, -- * From brillo, exported here for convenience loadBMP,@@ -54,6 +55,9 @@ ColorConvertible (promoteImage), ColorSpaceConvertible (convertImage), )+import Codec.Picture.WebP qualified as WebP+import Control.Exception (SomeException, try)+import Data.ByteString qualified as BS import Data.Vector.Storable (unsafeToForeignPtr) @@ -144,19 +148,33 @@ {-# INLINE loadJuicyPNG #-} -loadWith- :: (FilePath -> IO (Either String DynamicImage))- -> FilePath- -> IO (Maybe Picture)+{-| Loads a WebP image file into a Picture using the webp library.+Returns 'Nothing' if the file cannot be read or decoded.+Requires libwebp to be installed on the system.+-}+loadJuicyWebP :: FilePath -> IO (Maybe Picture)+loadJuicyWebP fp = do+ result <- try $ do+ bytes <- BS.readFile fp+ let !img = WebP.decodeRgba8 bytes+ return $ fromImageRGBA8 img+ return $ either (\(_ :: SomeException) -> Nothing) Just result+{-# INLINE loadJuicyWebP #-}+++loadWith ::+ (FilePath -> IO (Either String DynamicImage)) ->+ FilePath ->+ IO (Maybe Picture) loadWith reader fp = do eImg <- reader fp return $ either (const Nothing) fromDynamicImage eImg -loadWithMetadata- :: (FilePath -> IO (Either String (DynamicImage, Metadatas)))- -> FilePath- -> IO (Maybe (Picture, Metadatas))+loadWithMetadata ::+ (FilePath -> IO (Either String (DynamicImage, Metadatas))) ->+ FilePath ->+ IO (Maybe (Picture, Metadatas)) loadWithMetadata reader fp = do eImg <- reader fp return $
brillo-juicy.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: brillo-juicy-version: 0.2.4+version: 0.3.0 synopsis: Load any image supported by Juicy.Pixels in your brillo application @@ -18,17 +18,18 @@ maintainer: Adrian Sieber category: Graphics build-type: Simple+tested-with: GHC ==9.4.8 || ==9.6.7 || ==9.8.4 || ==9.10.3 || ==9.12.2 library default-language: GHC2021 exposed-modules: Brillo.Juicy build-depends:- , base >=4.8 && <5- , bmp >=1.2 && <1.3- , brillo >=1.13.3 && <1.15- , bytestring >=0.11 && <0.12- , JuicyPixels >=3.3 && <3.4- , vector >=0.13 && <0.14+ , base >=4.8 && <5+ , brillo >=2.0 && <3.0+ , bytestring >=0.11 && <0.13+ , JuicyPixels >=3.3 && <3.4+ , vector >=0.13 && <0.14+ , webp >=0.1 && <0.2 ghc-options: -O2 -Wall @@ -36,12 +37,12 @@ default-language: GHC2021 main-is: brillo-juicy.hs build-depends:- , base >=4.8 && <5- , bmp >=1.2 && <1.3- , brillo >=1.13.3 && <1.15- , bytestring >=0.11 && <0.12- , JuicyPixels >=3.3 && <3.4- , vector >=0.13 && <0.14+ , base >=4.8 && <5+ , brillo >=2.0 && <3.0+ , bytestring >=0.11 && <0.13+ , JuicyPixels >=3.3 && <3.4+ , vector >=0.13 && <0.14+ , webp >=0.1 && <0.2 ghc-options: -O2 -Wall -threaded other-modules: Brillo.Juicy
brillo-juicy.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE OverloadedStrings #-}+ module Main where import Brillo (