module Graphics.Image.IO.Base (
ImageFormat(..), Readable(..), Writable(..), Convertible(..),
) where
import qualified Data.ByteString as B (ByteString)
import qualified Data.ByteString.Lazy as BL (ByteString)
import Graphics.Image.ColorSpace
class Convertible a b where
convert :: a -> b
instance ToY cs e => Convertible (Pixel cs e) (Pixel Y Double) where
convert = toPixelY
instance ToYA cs e => Convertible (Pixel cs e) (Pixel YA Double) where
convert = toPixelYA
instance ToRGB cs e => Convertible (Pixel cs e) (Pixel RGB Double) where
convert = toPixelRGB
instance ToRGBA cs e => Convertible (Pixel cs e) (Pixel RGBA Double) where
convert = toPixelRGBA
class ImageFormat format where
data SaveOption format
ext :: format -> String
exts :: format -> [String]
exts f = [ext f]
isFormat :: String -> format -> Bool
isFormat e f = e `elem` exts f
class ImageFormat format => Readable img format where
decode :: format -> B.ByteString -> Either String img
class ImageFormat format => Writable img format where
encode :: format -> [SaveOption format] -> img -> BL.ByteString