avif 1.0.0.0 → 2.0.0.0
raw patch · 4 files changed
+14/−23 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Codec.Avif: ImageRGBA16 :: Image PixelRGBA16 -> RgbImage
- Codec.Avif: ImageRGBA8 :: Image PixelRGBA8 -> RgbImage
- Codec.Avif: data RgbImage
- Codec.Avif: decode :: ByteString -> RgbImage
+ Codec.Avif: decode :: ByteString -> Image PixelRGBA8
- Codec.Avif: decodeE :: ByteString -> Either AvifResult RgbImage
+ Codec.Avif: decodeE :: ByteString -> Either AvifResult (Image PixelRGBA8)
Files
- CHANGELOG.md +6/−0
- avif.cabal +1/−1
- src/Codec/Avif.chs +6/−13
- test/Spec.hs +1/−9
CHANGELOG.md view
@@ -1,5 +1,11 @@ # avif +# 1.1.0.0++ * Force decoding to use 8-bit color depth, avoiding failures on some images.+ * Remove `RgbImage`+ * Change signature of `decode`, `decodeE` back+ # 1.0.0.0 * Change signature of `decode` and `decodeE` to handle 16-bit images.
avif.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: avif-version: 1.0.0.0+version: 2.0.0.0 license: AGPL-3 license-file: LICENSE copyright: Copyright: (c) 2021 Vanessa McHale
src/Codec/Avif.chs view
@@ -2,19 +2,18 @@ , decode , decodeE , AvifResult (..)- , RgbImage (..) ) where import Codec.Avif.FFI-import Codec.Picture (Image (Image), PixelRGBA8, PixelRGBA16)+import Codec.Picture (Image (Image), PixelRGBA8) import Control.Exception (throw, throwIO) import qualified Data.ByteString as BS import qualified Data.ByteString.Unsafe as BS+import qualified Data.Vector.Storable as VS import Foreign.Ptr (castPtr) import Foreign.ForeignPtr (castForeignPtr, newForeignPtr, mallocForeignPtrBytes, withForeignPtr) import Foreign.Marshal (allocaBytes) import Foreign.Marshal.Utils (copyBytes)-import qualified Data.Vector.Storable as VS import System.IO.Unsafe (unsafePerformIO) #include <avif/avif.h>@@ -56,17 +55,12 @@ where (Image w h bytes) = img (imgPtr, _) = VS.unsafeToForeignPtr0 bytes --- | Cf. 'Codec.Picture.DynamicImage'------ @since 1.0.0.0-data RgbImage = ImageRGBA8 (Image PixelRGBA8) | ImageRGBA16 (Image PixelRGBA16)--decode :: BS.ByteString -> RgbImage+decode :: BS.ByteString -> (Image PixelRGBA8) decode = either throw id.decodeE {-# NOINLINE decodeE #-} -- | @since 0.1.2.0-decodeE :: BS.ByteString -> Either AvifResult RgbImage+decodeE :: BS.ByteString -> Either AvifResult (Image PixelRGBA8) decodeE bs = unsafePerformIO $ BS.unsafeUseAsCStringLen bs $ \(p, sz) -> do preDec <- avifDecoderCreate dec <- castForeignPtr <$> newForeignPtr avifDecoderDestroy (castPtr preDec)@@ -80,6 +74,7 @@ allocaBytes {# sizeof avifRGBImage #} $ \rgbImagePtr -> do avifRGBImageSetDefaults rgbImagePtr avifImg+ {# set avifRGBImage.depth #} rgbImagePtr 8 avifRGBImageAllocatePixels rgbImagePtr r <- avifImageYUVToRGB avifImg rgbImagePtr @@ -97,6 +92,4 @@ withForeignPtr outBytes $ \outPtr -> do copyBytes (castPtr outPtr) (castPtr pxPtr) sz'- let img | pxSz==8 = ImageRGBA16 (Image (fromIntegral w) (fromIntegral h) (VS.unsafeFromForeignPtr0 (castForeignPtr outBytes) sz'))- | pxSz==4 = ImageRGBA8 (Image (fromIntegral w) (fromIntegral h) (VS.unsafeFromForeignPtr0 outBytes sz'))- Right img <$ avifRGBImageFreePixels rgbImagePtr+ Right (Image (fromIntegral w) (fromIntegral h) (VS.unsafeFromForeignPtr0 outBytes sz')) <$ avifRGBImageFreePixels rgbImagePtr
test/Spec.hs view
@@ -23,14 +23,6 @@ let res = decodeE "aaaaa" in assertBool "fails on bad input" $ isLeft res -decodeRGB16 :: FilePath -> TestTree-decodeRGB16 fp = testCase fp $ do- res <- decodeE <$> BS.readFile fp- case res of- Right ImageRGBA16{} -> assertBool "decodes 16-bit" True- Right _ -> assertFailure "expected 16-bit color."- Left err -> assertFailure (show err)- decodeNoThrow :: FilePath -> TestTree decodeNoThrow fp = testCase fp $ do res <- decodeE <$> BS.readFile fp@@ -41,5 +33,5 @@ decEncNoThrow :: FilePath -> TestTree decEncNoThrow fp = testCase fp $ do bytes <- BS.readFile fp- let res = encode ((\(ImageRGBA8 img) -> img) $ decode bytes)+ let res = encode (decode bytes) assertBool "Doesn't throw exception" (res `deepseq` True)