I am using repa-devil
to read and write images. Now I need to programmatically create images. However, the Image
constructors (such as RGB
) in Data.Array.Repa.IO.DevIL
all require foreign memory buffer arrays. Do I have to go off and learn how to work with that foreign pointer stuff (which sounds scary)? Or can I convert an unboxed array to the type I need?
emptyImage :: RandomGen r => (Int, Int) -> Rand r Image
emptyImage (w,h) = do
xs <- getRandomRs (0, 255)
let ps = take (w*h*3) xs :: [Word8]
let arr = fromListUnboxed (Z :. w :. h :. (3::Int)) ps :: Array U DIM3 Word8
let arr2 = ???how can I convert arr??? :: Array F DIM3 Word8
return $ RGB arr2