File: BitmapInfo.hs

package info (click to toggle)
haskell-bmp 1.2.6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 124 kB
  • sloc: haskell: 911; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,283 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{-# OPTIONS_HADDOCK hide #-}
module Codec.BMP.BitmapInfo
        ( BitmapInfo    (..)
        , getBitmapInfoV3)
where

import Codec.BMP.BitmapInfoV3
import Codec.BMP.BitmapInfoV4
import Codec.BMP.BitmapInfoV5
import Control.Applicative 
import Data.Binary
import Data.Binary.Get


-- | A wrapper for the various image header types.
--   
data BitmapInfo
        = InfoV3 BitmapInfoV3
        | InfoV4 BitmapInfoV4
        | InfoV5 BitmapInfoV5
        deriving (Show)


instance Binary BitmapInfo where
 get = 
  (do 40 <- getWord32le
      info <- get
      return $ InfoV3 info)
  <|>
  (do 108 <- getWord32le
      info <- get
      return $ InfoV4 info)
  <|>
  (do 120 <- getWord32le
      info <- get
      return $ InfoV5 info)
  <|> 
  (error "Codec.BMP.BitmapInfo.get: unhandled header size")
        
 put xx
  = case xx of
        InfoV3 info     -> put info
        InfoV4 info     -> put info
        InfoV5 info     -> put info
        

-- | Get the common `BitmapInfoV3` structure from a `BitmapInfo`
getBitmapInfoV3 :: BitmapInfo -> BitmapInfoV3
getBitmapInfoV3 bi
 = case bi of
        InfoV3 info     -> info
        InfoV4 info     -> dib4InfoV3 info
        InfoV5 info     -> dib4InfoV3 $ dib5InfoV4 info