{-# OPTIONS_HADDOCK hide #-}
module Codec.BMP.Compression
(Compression(..))
where
import Data.Word
import Data.Binary
import Data.Binary.Get
import Data.Binary.Put
data Compression
= CompressionRGB
| CompressionRLE8
| CompressionRLE4
| CompressionBitFields
| CompressionJPEG
| CompressionPNG
| CompressionUnknown Word32
deriving (Int -> Compression -> ShowS
[Compression] -> ShowS
Compression -> String
(Int -> Compression -> ShowS)
-> (Compression -> String)
-> ([Compression] -> ShowS)
-> Show Compression
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Compression -> ShowS
showsPrec :: Int -> Compression -> ShowS
$cshow :: Compression -> String
show :: Compression -> String
$cshowList :: [Compression] -> ShowS
showList :: [Compression] -> ShowS
Show, Compression -> Compression -> Bool
(Compression -> Compression -> Bool)
-> (Compression -> Compression -> Bool) -> Eq Compression
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Compression -> Compression -> Bool
== :: Compression -> Compression -> Bool
$c/= :: Compression -> Compression -> Bool
/= :: Compression -> Compression -> Bool
Eq)
instance Binary Compression where
get :: Get Compression
get
= do Word32
c <- Get Word32
getWord32le
case Word32
c of
Word32
0 -> Compression -> Get Compression
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Compression -> Get Compression) -> Compression -> Get Compression
forall a b. (a -> b) -> a -> b
$ Compression
CompressionRGB
Word32
1 -> Compression -> Get Compression
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Compression -> Get Compression) -> Compression -> Get Compression
forall a b. (a -> b) -> a -> b
$ Compression
CompressionRLE8
Word32
2 -> Compression -> Get Compression
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Compression -> Get Compression) -> Compression -> Get Compression
forall a b. (a -> b) -> a -> b
$ Compression
CompressionRLE4
Word32
3 -> Compression -> Get Compression
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Compression -> Get Compression) -> Compression -> Get Compression
forall a b. (a -> b) -> a -> b
$ Compression
CompressionBitFields
Word32
4 -> Compression -> Get Compression
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Compression -> Get Compression) -> Compression -> Get Compression
forall a b. (a -> b) -> a -> b
$ Compression
CompressionJPEG
Word32
5 -> Compression -> Get Compression
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Compression -> Get Compression) -> Compression -> Get Compression
forall a b. (a -> b) -> a -> b
$ Compression
CompressionPNG
Word32
_ -> Compression -> Get Compression
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Compression -> Get Compression) -> Compression -> Get Compression
forall a b. (a -> b) -> a -> b
$ Word32 -> Compression
CompressionUnknown Word32
c
put :: Compression -> Put
put Compression
c
= case Compression
c of
Compression
CompressionRGB -> Word32 -> Put
putWord32le Word32
0
Compression
CompressionRLE8 -> Word32 -> Put
putWord32le Word32
1
Compression
CompressionRLE4 -> Word32 -> Put
putWord32le Word32
2
Compression
CompressionBitFields -> Word32 -> Put
putWord32le Word32
3
Compression
CompressionJPEG -> Word32 -> Put
putWord32le Word32
4
Compression
CompressionPNG -> Word32 -> Put
putWord32le Word32
5
CompressionUnknown Word32
x -> Word32 -> Put
putWord32le Word32
x