 
 
 -- Manipulating regions of interest:
-setROI (fromIntegral -> x,fromIntegral -> y) 
-       (fromIntegral -> w,fromIntegral -> h) 
-       image = withImage image $ \i -> 
+setROI (fromIntegral -> x,fromIntegral -> y)
+       (fromIntegral -> w,fromIntegral -> h)
+       image = withImage image $ \i ->
                             {#call wrapSetImageROI#} i x y w h
 
 resetROI image = withImage image $ \i ->
                   {#call cvResetImageROI#} i
 
-setCOI chnl image = withImage image $ \i -> 
+setCOI chnl image = withImage image $ \i ->
                             {#call cvSetImageCOI#} i (fromIntegral chnl)
 resetCOI image = withImage image $ \i ->
                   {#call cvSetImageCOI#} i 0


withImage :: Image c d -> (Ptr BareImage ->IO a) -> IO a
withImage (S i) op = withBareImage i op
--withGenNewImage (S i) op = withGenImage i op 

-- Ok. this is just the example why I need image types
withUniPtr with x fun = with x $ \y -> 
                    fun (castPtr y)

withGenImage = withUniPtr withImage



composeMultichannelImage :: (CreateImage (Image tp a)) => Maybe (Image GrayScale a) -> Maybe (Image GrayScale a) -> Maybe (Image GrayScale a) -> Maybe (Image GrayScale a) -> Tag tp -> Image tp a
composeMultichannelImage (c1)
                         (c2)
                         (c3)
                         (c4)
                         totag
    = unsafePerformIO $ do
        res <- create (size) -- TODO: Check channel count -- This is NOT correct
        withMaybe c1 $ \cc1 ->
         withMaybe c2 $ \cc2 ->
          withMaybe c3 $ \cc3 ->
           withMaybe c4 $ \cc4 ->
            withGenImage res $ \cres -> {#call cvMerge#} cc1 cc2 cc3 cc4 cres
        return res
    where
