From 701d77831f01bfbb42e8eaf10058fc53dfd4cc27 Mon Sep 17 00:00:00 2001 From: Michael Tolly Date: Sun, 6 Mar 2016 13:27:27 -0600 Subject: [PATCH] Use JP's dyn to rgb8 function --- jammittools.cabal | 2 +- src/Sound/Jammit/Internal/Image.hs | 23 ++--------------------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/jammittools.cabal b/jammittools.cabal index c9deba8..885813e 100644 --- a/jammittools.cabal +++ b/jammittools.cabal @@ -42,7 +42,7 @@ library , process >= 1.1.0.2 && < 1.5 , temporary >= 1.1.2.5 && < 1.3 , transformers >= 0.3.0.0 && < 0.6 - , JuicyPixels >= 3.2.2 && < 3.3 + , JuicyPixels >= 3.2.7 && < 3.3 , HPDF >= 1.4.9 && < 1.5 , bytestring >= 0.10.4.0 && < 0.11 , conduit >= 1.2.3.1 && < 1.3 diff --git a/src/Sound/Jammit/Internal/Image.hs b/src/Sound/Jammit/Internal/Image.hs index cef857b..0408066 100644 --- a/src/Sound/Jammit/Internal/Image.hs +++ b/src/Sound/Jammit/Internal/Image.hs @@ -4,7 +4,7 @@ module Sound.Jammit.Internal.Image ) where import qualified Codec.Picture as P -import Codec.Picture.Types (convertImage, dropAlphaLayer, promoteImage) +import Codec.Picture.Types (convertImage) import Control.Monad (forM_, replicateM) import Control.Monad.IO.Class (MonadIO) import Control.Monad.Trans.Class (lift) @@ -13,32 +13,13 @@ import qualified Data.ByteString.Lazy as BL import qualified Data.Conduit as C import Data.Maybe (catMaybes) import qualified Data.Vector.Storable as V -import Data.Bits (shiftR) import Sound.Jammit.Internal.TempIO loadPNG :: FilePath -> IO (P.Image P.PixelRGB8) loadPNG fp = do Right dyn <- P.readImage fp - return $ anyToRGB8 dyn - -anyToRGB8 :: P.DynamicImage -> P.Image P.PixelRGB8 -anyToRGB8 dyn = case dyn of - P.ImageY8 i -> promoteImage i - P.ImageY16 i -> anyToRGB8 $ P.ImageRGB16 $ promoteImage i - P.ImageYF i -> anyToRGB8 $ P.ImageRGBF $ promoteImage i - P.ImageYA8 i -> promoteImage i - P.ImageYA16 i -> anyToRGB8 $ P.ImageRGBA16 $ promoteImage i - P.ImageRGB8 i -> i - P.ImageRGB16 i -> P.pixelMap (\(P.PixelRGB16 r g b) -> P.PixelRGB8 (f r) (f g) (f b)) i - where f w16 = fromIntegral $ w16 `shiftR` 8 - P.ImageRGBF i -> P.pixelMap (\(P.PixelRGBF r g b) -> P.PixelRGB8 (f r) (f g) (f b)) i - where f w16 = floor $ min 0xFF $ w16 * 0x100 - P.ImageRGBA8 i -> dropAlphaLayer i - P.ImageRGBA16 i -> anyToRGB8 $ P.ImageRGB16 $ dropAlphaLayer i - P.ImageYCbCr8 i -> convertImage i - P.ImageCMYK8 i -> convertImage i - P.ImageCMYK16 i -> anyToRGB8 $ P.ImageRGB16 $ convertImage i + return $ P.convertRGB8 dyn pngChunks :: (MonadIO m) => Int -> [FilePath] -> C.Source m (P.Image P.PixelRGB8)