module OpenCV.Internal.Core.Types.Mat.Marshal
( marshalDepth
, unmarshalDepth
, marshalFlags
, unmarshalFlags
) where
import "base" Data.Bits
import "base" Data.Int
import "base" Data.Monoid ( (<>) )
import "this" OpenCV.Internal.Core.Types.Mat.Depth
c'CV_8U = 0
c'CV_8U :: (Num a) => a
c'CV_8S = 1
c'CV_8S :: (Num a) => a
c'CV_16U = 2
c'CV_16U :: (Num a) => a
c'CV_16S = 3
c'CV_16S :: (Num a) => a
c'CV_32S = 4
c'CV_32S :: (Num a) => a
c'CV_32F = 5
c'CV_32F :: (Num a) => a
c'CV_64F = 6
c'CV_64F :: (Num a) => a
c'CV_USRTYPE1 = 7
c'CV_USRTYPE1 :: (Num a) => a
marshalDepth :: Depth -> Int32
marshalDepth = \case
Depth_8U -> c'CV_8U
Depth_8S -> c'CV_8S
Depth_16U -> c'CV_16U
Depth_16S -> c'CV_16S
Depth_32S -> c'CV_32S
Depth_32F -> c'CV_32F
Depth_64F -> c'CV_64F
Depth_USRTYPE1 -> c'CV_USRTYPE1
unmarshalDepth :: Int32 -> Depth
unmarshalDepth n
| n == c'CV_8U = Depth_8U
| n == c'CV_8S = Depth_8S
| n == c'CV_16U = Depth_16U
| n == c'CV_16S = Depth_16S
| n == c'CV_32S = Depth_32S
| n == c'CV_32F = Depth_32F
| n == c'CV_64F = Depth_64F
| n == c'CV_USRTYPE1 = Depth_USRTYPE1
| otherwise = error $ "unknown depth " <> show n
c'CV_CN_SHIFT = 3
c'CV_CN_SHIFT :: (Num a) => a
marshalFlags
:: Depth
-> Int32
-> Int32
marshalFlags depth cn =
marshalDepth depth
.|. ((cn 1) `unsafeShiftL` c'CV_CN_SHIFT)
c'CV_CN_MAX = 512
c'CV_CN_MAX :: (Num a) => a
c'CV_MAT_DEPTH_MASK = 7
c'CV_MAT_DEPTH_MASK :: (Num a) => a
unmarshalFlags :: Int32 -> (Depth, Int32)
unmarshalFlags n =
( unmarshalDepth $ n .&. c'CV_MAT_DEPTH_MASK
, 1 + ((n `unsafeShiftR` c'CV_CN_SHIFT) .&. (c'CV_CN_MAX 1))
)