never executed always true always false
    1 module OpenCV.Unsafe
    2     ( unsafeCoerceMat
    3     , unsafeCoerceMatM
    4       -- * Mutable Matrix
    5     , unsafeFreeze
    6     , unsafeThaw
    7     , unsafeRead
    8     , unsafeWrite
    9     ) where
   10 
   11 import "base" Foreign.Ptr ( plusPtr )
   12 import "base" Foreign.Storable ( Storable, peek, poke, sizeOf )
   13 import "primitive" Control.Monad.Primitive
   14     ( PrimMonad, PrimState, unsafePrimToPrim )
   15 import "this" OpenCV.Internal.Core.Types.Mat
   16 import "this" OpenCV.Internal.Mutable
   17 
   18 unsafeRead
   19     :: forall m shape channels depth value
   20      . (PrimMonad m, Storable value)
   21     => Mut (Mat shape channels depth) (PrimState m)
   22     -> [Int] -- ^ position
   23     -> Int -- ^ channel
   24     -> m value
   25 unsafeRead matM pos channel =
   26     unsafePrimToPrim $ withMatData (unMut matM) $ \step dataPtr ->
   27       let elemPtr = matElemAddress dataPtr (fromIntegral <$> step) pos
   28       in peek (elemPtr `plusPtr` (channel * sizeOf dummyValue))
   29   where
   30     dummyValue :: value
   31     dummyValue = error "dummy"
   32 
   33 unsafeWrite
   34     :: (PrimMonad m, Storable value)
   35     => Mut (Mat shape channels depth) (PrimState m)
   36     -> [Int] -- ^ position
   37     -> Int -- ^ channel
   38     -> value
   39     -> m ()
   40 unsafeWrite matM pos channel value =
   41     unsafePrimToPrim $ withMatData (unMut matM) $ \step dataPtr ->
   42       let elemPtr = matElemAddress dataPtr (fromIntegral <$> step) pos
   43       in poke (elemPtr `plusPtr` (channel * sizeOf value)) value