{-# OPTIONS_HADDOCK hide #-}
module Codec.BMP.Error
        (Error(..))
where
import Codec.BMP.Compression
import Data.Word


-- | Things that can go wrong when loading a BMP file.
data Error
        -- | Magic number was not at the start of the file, 
        --   so this probably isn't a BMP file.
        = ErrorBadMagic
        { Error -> Word16
errorMagic            :: Word16 }

        -- | File is too short to contain a file header.
        | ErrorFileHeaderTruncated

        -- | File is too short to contain an image header.
        | ErrorImageHeaderTruncated

        -- | File is too short to contain the image data.
        | ErrorImageDataTruncated
        { Error -> Int
errorBytesNeeded      :: Int
        , Error -> Int
errorBytesAvailable   :: Int }

        -- | Reserved fields should be zero.
        | ErrorReservedFieldNotZero

        -- | The offset to the image data from the file header doesn't
        --   point anywhere sensible.
        | ErrorDodgyFileHeaderFieldOffset
        { Error -> Word32
errorFileHeaderOffset :: Word32 }

        -- | We handle V3 V4 and V5 image headers, but the size of 
        --   the header indicates it has some other format.
        | ErrorUnhandledBitmapHeaderSize
        { Error -> Word32
errorBitmapHeaderSize :: Word32 }

        -- | We only handle single color planes.
        | ErrorUnhandledPlanesCount
        { Error -> Word16
errorPlanesCount      :: Word16 }

        -- | We only handle 24 and 32 bit images.
        | ErrorUnhandledColorDepth
        { Error -> Word16
errorColorDepth       :: Word16 }

        -- | We only handle uncompressed images.
        | ErrorUnhandledCompressionMode
        { Error -> Compression
errorCompression      :: Compression}

        -- | Mismatch between the image size stated in the header
        --   and that which is calculuated from the other fields.
        | ErrorImagePhysicalSizeMismatch 
        { Error -> Word32
errorImageSizeFromHeader  :: Word32
        , Error -> Word32
errorImageSizeOfBuffer    :: Word32 }

        -- | Something went wrong in the library.
        | ErrorInternalErrorPleaseReport
        deriving (Error -> Error -> Bool
(Error -> Error -> Bool) -> (Error -> Error -> Bool) -> Eq Error
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Error -> Error -> Bool
== :: Error -> Error -> Bool
$c/= :: Error -> Error -> Bool
/= :: Error -> Error -> Bool
Eq, Int -> Error -> ShowS
[Error] -> ShowS
Error -> String
(Int -> Error -> ShowS)
-> (Error -> String) -> ([Error] -> ShowS) -> Show Error
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Error -> ShowS
showsPrec :: Int -> Error -> ShowS
$cshow :: Error -> String
show :: Error -> String
$cshowList :: [Error] -> ShowS
showList :: [Error] -> ShowS
Show)