{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Graphics.Image.IO.Base (
ImageFormat(..), Readable(..), Writable(..), Convertible(..), Seq(..), ComplexWritable
) where
import qualified Data.ByteString as B (ByteString)
import qualified Data.ByteString.Lazy as BL (ByteString)
import Graphics.Image.ColorSpace
import Graphics.Image.Interface as I
import Graphics.Image.Processing.Complex (imagPartI, realPartI)
import Graphics.Image.Processing.Geometric (leftToRight)
class Convertible cs e where
convert :: (ToYA cs' e', ToRGBA cs' e', Array arr cs' e', Array arr cs e) =>
Image arr cs' e' -> Image arr cs e
instance Convertible Y Double where
convert = toImageY
instance Convertible YA Double where
convert = toImageYA
instance Convertible RGB Double where
convert = toImageRGB
instance Convertible RGBA Double where
convert = toImageRGBA
newtype Seq f = Seq f
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
type ComplexWritable format arr cs e = ( Array arr cs e, Array arr cs (Complex e)
, RealFloat e, Applicative (Pixel cs)
, Writable (Image arr cs e) format )
instance ComplexWritable format arr cs e => Writable (Image arr cs (Complex e)) format where
encode format opts !imgC =
encode format opts (leftToRight (realPartI imgC) (imagPartI imgC))