module Codec.Picture (
readImage
, decodeImage
, BmpEncodable
, writeBitmap
, encodeBitmap
, decodeBitmap
, encodeDynamicBitmap
, writeDynamicBitmap
, readJpeg
, decodeJpeg
, PngSavable( .. )
, readPng
, decodePng
, writePng
, encodeDynamicPng
, writeDynamicPng
, Image( .. )
, DynamicImage( .. )
, Pixel( .. )
, Pixel8
, PixelYA8( .. )
, PixelRGB8( .. )
, PixelRGBA8( .. )
, PixelYCbCr8( .. )
) where
import Control.Applicative( (<$>) )
import Codec.Picture.Bitmap
import Codec.Picture.Jpg( readJpeg, decodeJpeg )
import Codec.Picture.Png( PngSavable( .. ), readPng, decodePng, writePng
, encodeDynamicPng , writeDynamicPng )
import Codec.Picture.Types
import qualified Data.ByteString as B
eitherLoad :: c -> [(String, c -> Either String b)] -> Either String b
eitherLoad v = inner ""
where inner errAcc [] = Left $ "Cannot load file\n" ++ errAcc
inner errAcc ((hdr, f) : rest) = case f v of
Left err -> inner (errAcc ++ hdr ++ " " ++ err ++ "\n") rest
Right rez -> Right rez
readImage :: FilePath -> IO (Either String DynamicImage)
readImage path = decodeImage <$> B.readFile path
decodeImage :: B.ByteString -> Either String DynamicImage
decodeImage str = eitherLoad str [("Jpeg", decodeJpeg)
,("PNG", decodePng)
,("Bitmap", decodeBitmap)
]