 , bgrToRgb
 , rgbToBgr
 , cloneTo64F
-, unsafeImageTo32F 
-, unsafeImageTo64F 
-, unsafeImageTo8Bit 
+, unsafeImageTo32F
+, unsafeImageTo64F
+, unsafeImageTo8Bit
 
 -- * Low level access operations
 , BareImage(..)


withRawImageData :: Image c d -> (Int -> Ptr Word8 -> IO a) -> IO a
withRawImageData (S i) op = withBareImage i $ \pp-> do
                             d  <- {#get IplImage->imageData#} pp 
                             wd <- {#get IplImage->widthStep#} pp
                             op (fromIntegral wd) (castPtr d)


--   polymorphic enough to cause run time errors if the declared and actual types of the
--   images do not match. Use with care.
unsafeloadUsing x p n = do
  exists <- doesFileExist n
  if not exists then return Nothing
    else do
    mi <- withCString n $ \name ->
      creatingMaybeBareImage ({#call cvLoadImage #} name p)
    case mi of
      Nothing -> return Nothing
      Just i -> do
        bw <- x i
        return . Just . S $ bw

loadImage :: FilePath -> IO (Maybe (Image GrayScale D32))
loadImage = unsafeloadUsing imageTo32F 0
