 
 
 
-convert8UTo :: CInt -> CInt -> BareImage -> BareImage
+convert8UTo :: CvtCodes -> CInt -> BareImage -> BareImage
 convert8UTo code channels img = unsafePerformIO $ creatingBareImage $ do
     res <- {#call wrapCreateImage8U#} w h channels
     withBareImage img $ \cimg ->
-        {#call cvCvtColor#} (castPtr cimg) (castPtr res) code
+        {#call cvCvtColor#} (castPtr cimg) (castPtr res) (fromIntegral . fromEnum $ code)
     return res
  where
     (fromIntegral -> w,fromIntegral -> h) = getSize img
 
-convertTo :: CInt -> CInt -> BareImage -> BareImage
+convertTo :: CvtCodes -> CInt -> BareImage -> BareImage
 convertTo code channels img = unsafePerformIO $ creatingBareImage $ do
     res <- {#call wrapCreateImage32F#} w h channels
     withBareImage img $ \cimg ->
-        {#call cvCvtColor#} (castPtr cimg) (castPtr res) code
+        {#call cvCvtColor#} (castPtr cimg) (castPtr res) (fromIntegral . fromEnum $ code)
     return res
  where
     (fromIntegral -> w,fromIntegral -> h) = getSize img

data BGR

data LAB
data RGBA
data LAB_Channel = LAB_L | LAB_A | LAB_B deriving (Eq,Ord,Enum)

-- | Type family for expressing which channels a colorspace contains. This needs to be fixed wrt. the BGR color space.
type family ChannelOf a :: *
type instance ChannelOf RGB_Channel = RGB
type instance ChannelOf LAB_Channel = LAB

-- Bit Depths
type D8  = Word8


{#enum CvtFlags {}#}

rgbToLab :: Image RGB D32 -> Image LAB D32
rgbToLab = S . convertTo RGB2Lab 3 . unS

rgbToYUV :: Image RGB D32 -> Image YUV D32
rgbToYUV = S . convertTo RGB2YUV 3 . unS

rgbToGray :: Image RGB D32 -> Image GrayScale D32
rgbToGray = S . convertTo RGB2GRAY 1 . unS

rgbToGray8 :: Image RGB D8 -> Image GrayScale D8
rgbToGray8 = S . convert8UTo RGB2GRAY 1 . unS

grayToRGB :: Image GrayScale D32 -> Image RGB D32
grayToRGB = S . convertTo GRAY2BGR 3 . unS

bgrToRgb :: Image BGR D8 -> Image RGB D8
bgrToRgb = S . swapRB . unS
