Codec.BMP
Description
Reading and writing uncompressed BMP files.
Reading works for both uncompressed 24bit RGB WindowsV3 and 32bit RGBA WindowsV4 formats.
Writing is limited to the uncompressed 24bit RGB WindowsV3 format.
We don't support the plain OS/2 BitmapCoreHeader and BitmapCoreHeader2 image headers, but I haven't yet seen one of these in the wild.
To write a file do something like:
do let rgba = Data.ByteString.pack [some list of Word8s] let bmp = packRGBA32ToBMP width height rgba writeBMP fileName bmp
To read a file do something like:
do Right bmp <- readBMP fileName let rgba = unpackBMPToRGBA32 bmp let (width, height) = bmpDimensions bmp ...
- data BMP = BMP {}
- data FileHeader = FileHeader {}
- data BitmapInfo
- data BitmapInfoV3 = BitmapInfoV3 {}
- data BitmapInfoV4 = BitmapInfoV4 {}
- data BitmapInfoV5 = BitmapInfoV5 {}
- data Compression
- data CIEXYZ = CIEXYZ Word32 Word32 Word32
- data Error
- = ErrorReadOfFileHeaderFailed
- | ErrorReadOfImageHeaderFailed
- | ErrorReadOfImageDataFailed
- | ErrorBadMagic Word16
- | ErrorReservedFieldNotZero
- | ErrorDodgyFileHeaderFieldOffset Int
- | ErrorDodgyFileHeaderFieldFileSize Int
- | ErrorFileIsTruncated
- | ErrorUnhandledBitmapHeaderSize Int
- | ErrorUnhandledPlanesCount Int
- | ErrorUnhandledColorDepth Int
- | ErrorUnhandledCompressionMode
- | ErrorZeroImageSize
- | ErrorLacksWholeNumberOfLines
- readBMP :: FilePath -> IO (Either Error BMP)
- writeBMP :: FilePath -> BMP -> IO ()
- hGetBMP :: Handle -> IO (Either Error BMP)
- hPutBMP :: Handle -> BMP -> IO ()
- packRGBA32ToBMP :: Int -> Int -> ByteString -> BMP
- unpackBMPToRGBA32 :: BMP -> ByteString
- bmpDimensions :: BMP -> (Int, Int)
Documentation
A BMP image. For an uncompressed image, the image data contains triples of BGR component values. Each line may also have zero pad values on the end, to bring them up to a multiple of 4 bytes in length.
Constructors
BMP | |
Fields |
data FileHeader Source
BMP file header.
Constructors
FileHeader | |
Fields
|
Instances
data BitmapInfo Source
A wrapper for the various image header types.
Constructors
InfoV3 BitmapInfoV3 | |
InfoV4 BitmapInfoV4 | |
InfoV5 BitmapInfoV5 |
Instances
data BitmapInfoV3 Source
Device Independent Bitmap (DIB) header for Windows V3.
Constructors
BitmapInfoV3 | |
Fields
|
Instances
data BitmapInfoV4 Source
Device Independent Bitmap (DIB) header for Windows V4 (95 and newer)
Constructors
BitmapInfoV4 | |
Fields
|
Instances
data BitmapInfoV5 Source
Device Independent Bitmap (DIB) header for Windows V5 (98/2000 and newer)
Constructors
BitmapInfoV5 | |
Fields
|
Instances
data Compression Source
Constructors
CompressionRGB | |
CompressionRLE8 | |
CompressionRLE4 | |
CompressionBitFields | |
CompressionJPEG | |
CompressionPNG | |
CompressionUnknown Word32 |
Instances
Contains the XYZ coordinates of a specific color in a specified color space.
Things that can go wrong when loading a BMP file.
Constructors
hGetBMP :: Handle -> IO (Either Error BMP)Source
Get a BMP image from a file handle.
The file is checked for problems and unsupported features when read.
If there is anything wrong this gives an Error
instead.
Arguments
:: Int | Width of image. |
-> Int | Height of image. |
-> ByteString | A string of RGBA component values. Must have length ( |
-> BMP |
Pack a string of RGBA component values into a BMP image.
If the given dimensions don't match the input string then error
.
This currently ignores the alpha component of the input string and produces a 24bit RGB image.
unpackBMPToRGBA32 :: BMP -> ByteStringSource
Unpack a BMP image to a string of RGBA component values.
bmpDimensions :: BMP -> (Int, Int)Source
Get the width and height of an image. It's better to use this function than to access the headers directly.