module CV.Conversions (
copyCArrayToImage
,copy8UCArrayToImage
,copyImageToCArray
,copyFCArrayToImage
,copyImageToFCArray
,copyComplexCArrayToImage
,copyImageToComplexCArray
,copyImageToExistingCArray
,unsafe8UC_RGBFromPtr
,unsafe8UC_BGRFromPtr
,acquireImageSlowF'
,acquireImageSlow'
,acquireImageSlow8URGB'
) where
import Data.Complex as C
import CV.Image
import Data.Word
import Data.Array.CArray
import Data.Array.IArray
import Foreign.C.Types
import Foreign.Ptr
import Foreign.Storable.Complex
import System.IO.Unsafe
unsafe8UC_RGBFromPtr :: (Int,Int) -> Ptr Word8 -> IO (Image RGB D8)
unsafe8UC_RGBFromPtr (w,h) ptr = S `fmap` creatingBareImage (acquireImageSlow8URGB' w h ptr)
unsafe8UC_BGRFromPtr :: (Int,Int) -> Ptr Word8 -> IO (Image RGB D8)
unsafe8UC_BGRFromPtr (w,h) ptr = S `fmap` creatingBareImage (acquireImageSlow8UBGR' w h ptr)
copy8UCArrayToImage :: CArray (Int,Int) Word8 -> Image GrayScale D8
copy8UCArrayToImage carr = S $ unsafePerformIO $
creatingBareImage (withCArray carr (acquireImageSlow8U' w h))
where
((sx,sy),(ex,ey)) = bounds carr
(w,h) = (fromIntegral $ exsx+1, fromIntegral $ eysy+1)
copyCArrayToImage :: CArray (Int,Int) Double -> Image GrayScale D32
copyCArrayToImage carr = S $ unsafePerformIO $
creatingBareImage (withCArray carr (acquireImageSlow' w h))
where
((sx,sy),(ex,ey)) = bounds carr
(w,h) = (fromIntegral $ exsx+1, fromIntegral $ eysy+1)
copyFCArrayToImage :: CArray (Int,Int) Float -> Image GrayScale D32
copyFCArrayToImage carr = S $ unsafePerformIO $
creatingBareImage (withCArray carr (acquireImageSlowF' w h))
where
((sx,sy),(ex,ey)) = bounds carr
(w,h) = (fromIntegral $ exsx+1, fromIntegral $ eysy+1)
copyImageToFCArray :: Image GrayScale D32 -> CArray (Int,Int) Float
copyImageToFCArray (S img) = unsafePerformIO $
withBareImage img $ \cimg ->
createCArray ((0,0),(w1,h1)) (exportImageSlowF' cimg)
where
(w,h) = getSize img
copyComplexCArrayToImage :: CArray (Int,Int) (C.Complex Double) -> Image GrayScale D32
copyComplexCArrayToImage carr = S $ unsafePerformIO $
creatingBareImage (withCArray carr (acquireImageSlowComplex' w h))
where
((sx,sy),(ex,ey)) = bounds carr
(w,h) = (fromIntegral $ exsx+1, fromIntegral $ eysy+1)
copyImageToCArray :: Image GrayScale D32 -> CArray (Int,Int) Double
copyImageToCArray (S img) = unsafePerformIO $
withBareImage img $ \cimg ->
createCArray ((0,0),(w1,h1)) (exportImageSlow' cimg)
where
(w,h) = getSize img
copyImageToExistingCArray (S img) arr =
withBareImage img $ \cimg ->
withCArray arr $ \carr -> (exportImageSlow' cimg carr)
where
(w,h) = getSize img
copyImageToComplexCArray :: Image GrayScale D32 -> CArray (Int,Int) (C.Complex Double)
copyImageToComplexCArray (S img) = unsafePerformIO $
withBareImage img $ \cimg ->
createCArray ((0,0),(w1,h1)) (exportImageSlowComplex' cimg)
where
(w,h) = getSize img
foreign import ccall safe "CV/cvWrapLeo.h exportImageSlow"
exportImageSlow' :: ((Ptr (BareImage)) -> ((Ptr Double) -> (IO ())))
foreign import ccall safe "CV/cvWrapLeo.h exportImageSlowF"
exportImageSlowF' :: ((Ptr (BareImage)) -> ((Ptr Float) -> (IO ())))
foreign import ccall safe "CV/cvWrapLeo.h exportImageSlowComplex"
exportImageSlowComplex' :: ((Ptr (BareImage)) -> ((Ptr (C.Complex Double)) -> (IO ())))
foreign import ccall safe "CV/cvWrapLeo.h acquireImageSlow"
acquireImageSlow' :: (Int -> (Int -> ((Ptr Double) -> (IO (Ptr (BareImage))))))
foreign import ccall safe "CV/cvWrapLeo.h acquireImageSlowF"
acquireImageSlowF' :: (Int -> (Int -> ((Ptr Float) -> (IO (Ptr (BareImage))))))
foreign import ccall safe "CV/cvWrapLeo.h acquireImageSlow8URGB"
acquireImageSlow8URGB' :: (Int -> (Int -> ((Ptr Word8) -> (IO (Ptr (BareImage))))))
foreign import ccall safe "CV/cvWrapLeo.h acquireImageSlow8UBGR"
acquireImageSlow8UBGR' :: (Int -> (Int -> ((Ptr Word8) -> (IO (Ptr (BareImage))))))
foreign import ccall safe "CV/cvWrapLeo.h acquireImageSlow8U"
acquireImageSlow8U' :: (Int -> (Int -> ((Ptr Word8) -> (IO (Ptr (BareImage))))))
foreign import ccall safe "CV/cvWrapLeo.h acquireImageSlowComplex"
acquireImageSlowComplex' :: (Int -> (Int -> ((Ptr (C.Complex Double)) -> (IO (Ptr (BareImage))))))