-
Notifications
You must be signed in to change notification settings - Fork 23
/
Types.hsc
97 lines (75 loc) · 2.4 KB
/
Types.hsc
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{-# LANGUAGE CPP, ForeignFunctionInterface, NoMonomorphismRestriction, RankNTypes #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Graphics.ImageMagick.MagickWand.FFI.Types
where
#include <wand/MagickWand.h>
import Control.Monad
import Foreign
import Foreign.C.Types
data PixelIterator
data MagickWand
data PixelWand
data DrawingWand
data Image
data PointInfo = PointInfo {piX, piY :: CDouble}
deriving (Eq, Show)
instance Storable PointInfo where
sizeOf = const #size PointInfo
alignment _ = 1
poke p foo = do
#{poke PointInfo, x} p $ piX foo
#{poke PointInfo, y} p $ piY foo
peek p = return PointInfo
`ap` (#{peek PointInfo, x} p)
`ap` (#{peek PointInfo, y} p)
newtype MagickBooleanType = MagickBooleanType { unMagickBooleanType :: CInt}
deriving (Eq, Show, Storable)
#{enum MagickBooleanType, MagickBooleanType
, mFalse = MagickFalse
, mTrue = MagickTrue
}
newtype ClassType = ClassType { unClassType :: CInt}
deriving (Eq, Show)
#{enum ClassType, ClassType
, undefinedClass = UndefinedClass
, directClass = DirectClass
, pseudoClass = PseudoClass
}
newtype LineCap = LineCap { unLineCap :: CInt }
#{enum LineCap, LineCap
, udefinedCap = UndefinedCap
, buttCap = ButtCap
, roundCap = RoundCap
, squareCap = SquareCap
}
newtype LineJoin = LineJoin { unLineJoin :: CInt }
#{enum LineJoin, LineJoin
, undefinedJoin = UndefinedJoin
, mitterJoin = MiterJoin
, roundJoin = RoundJoin
, bevelJoin = BevelJoin
}
newtype FillRule = FillRule { unFillRule :: CInt }
#{enum FillRule, FillRule
, undefinedRule = UndefinedRule
, evenOddRule = EvenOddRule
, nonZeroRule = NonZeroRule
}
data MagickPixelPacket
instance Storable MagickPixelPacket where
sizeOf = const #size MagickPixelPacket
alignment _ = 1
peek = error "not yet implemented"
poke = error "not yet implemented"
getPixelRed, getPixelGreen, getPixelBlue, getPixelIndex
:: Storable a => Ptr b -> IO a
getPixelRed = #peek MagickPixelPacket, red
getPixelGreen = #peek MagickPixelPacket, green
getPixelBlue = #peek MagickPixelPacket, blue
getPixelIndex = #peek MagickPixelPacket, index
setPixelRed, setPixelGreen, setPixelBlue, setPixelIndex
:: Storable a => Ptr b -> a -> IO ()
setPixelRed = #poke MagickPixelPacket, red
setPixelGreen = #poke MagickPixelPacket, green
setPixelBlue = #poke MagickPixelPacket, blue
setPixelIndex = #poke MagickPixelPacket, index