never executed always true always false
1 {-# language CPP #-}
2
3 #ifndef ENABLE_INTERNAL_DOCUMENTATION
4 {-# OPTIONS_HADDOCK hide #-}
5 #endif
6
7 module OpenCV.Internal.Core.Types.Mat.Marshal
8 ( marshalDepth
9 , unmarshalDepth
10 , marshalFlags
11 , unmarshalFlags
12 ) where
13
14 import "base" Data.Bits
15 import "base" Data.Int
16 import "base" Data.Monoid ( (<>) )
17 import "this" OpenCV.Internal.Core.Types.Mat.Depth
18
19 --------------------------------------------------------------------------------
20
21 #include <bindings.dsl.h>
22 #include "opencv2/core.hpp"
23
24 #include "namespace.hpp"
25
26 --------------------------------------------------------------------------------
27
28 #num CV_8U
29 #num CV_8S
30 #num CV_16U
31 #num CV_16S
32 #num CV_32S
33 #num CV_32F
34 #num CV_64F
35 #num CV_USRTYPE1
36
37 marshalDepth :: Depth -> Int32
38 marshalDepth = \case
39 Depth_8U -> c'CV_8U
40 Depth_8S -> c'CV_8S
41 Depth_16U -> c'CV_16U
42 Depth_16S -> c'CV_16S
43 Depth_32S -> c'CV_32S
44 Depth_32F -> c'CV_32F
45 Depth_64F -> c'CV_64F
46 Depth_USRTYPE1 -> c'CV_USRTYPE1
47
48 unmarshalDepth :: Int32 -> Depth
49 unmarshalDepth n
50 | n == c'CV_8U = Depth_8U
51 | n == c'CV_8S = Depth_8S
52 | n == c'CV_16U = Depth_16U
53 | n == c'CV_16S = Depth_16S
54 | n == c'CV_32S = Depth_32S
55 | n == c'CV_32F = Depth_32F
56 | n == c'CV_64F = Depth_64F
57 | n == c'CV_USRTYPE1 = Depth_USRTYPE1
58 | otherwise = error $ "unknown depth " <> show n
59
60 #num CV_CN_SHIFT
61
62 marshalFlags
63 :: Depth
64 -> Int32 -- ^ Number of channels
65 -> Int32
66 marshalFlags depth cn =
67 marshalDepth depth
68 .|. ((cn - 1) `unsafeShiftL` c'CV_CN_SHIFT)
69
70 #num CV_CN_MAX
71 #num CV_MAT_DEPTH_MASK
72
73 unmarshalFlags :: Int32 -> (Depth, Int32)
74 unmarshalFlags n =
75 ( unmarshalDepth $ n .&. c'CV_MAT_DEPTH_MASK
76 , 1 + ((n `unsafeShiftR` c'CV_CN_SHIFT) .&. (c'CV_CN_MAX - 1))
77 )