{-# OPTIONS_HADDOCK hide #-}moduleCodec.BMP.FileHeader(FileHeader(..),bmpMagic,sizeOfFileHeader,checkFileHeader)whereimportCodec.BMP.BitmapInfoimportCodec.BMP.ErrorimportData.BinaryimportData.Binary.GetimportData.Binary.Put-- File Headers ------------------------------------------------------------------------------------- | BMP file header.dataFileHeader=FileHeader{-- | Magic numbers 0x42 0x4dfileHeaderType::Word16-- | Size of the file, in bytes.,fileHeaderFileSize::Word32-- | Reserved, must be zero.,fileHeaderReserved1::Word16-- | Reserved, must be zero.,fileHeaderReserved2::Word16-- | Offset in bytes to the start of the pixel data.,fileHeaderOffset::Word32}deriving(Show)-- | Size of a file header (in bytes).sizeOfFileHeader::IntsizeOfFileHeader=14-- | Magic number that should come at the start of a BMP file.bmpMagic::Word16bmpMagic=0x4d42instanceBinaryFileHeaderwhereget=dot<-getWord16lesize<-getWord32leres1<-getWord16leres2<-getWord16leoffset<-getWord32lereturn$FileHeader{fileHeaderType=t,fileHeaderFileSize=size,fileHeaderReserved1=res1,fileHeaderReserved2=res2,fileHeaderOffset=offset}putheader=doputWord16le$fileHeaderTypeheaderputWord32le$fileHeaderFileSizeheaderputWord16le$fileHeaderReserved1headerputWord16le$fileHeaderReserved2headerputWord32le$fileHeaderOffsetheader-- | Check a file header for problems and unsupported features.checkFileHeader::FileHeader->MaybeErrorcheckFileHeaderheader|fileHeaderTypeheader/=bmpMagic=Just$ErrorBadMagic(fileHeaderTypeheader)|fileHeaderFileSizeheader<fromIntegral(sizeOfFileHeader+sizeOfBitmapInfoV3)=Just$ErrorDodgyFileHeaderFieldFileSize$fromIntegral$fileHeaderFileSizeheader|fileHeaderReserved1header/=0=Just$ErrorReservedFieldNotZero|fileHeaderReserved2header/=0=Just$ErrorReservedFieldNotZero|fromIntegral(fileHeaderOffsetheader)/=sizeOfFileHeader+sizeOfBitmapInfoV3=Just$ErrorDodgyFileHeaderFieldOffset$fromIntegral$fileHeaderOffsetheader|otherwise=Nothing