module Examples.Utils.PPM where import qualified Data.Array.Accelerate as A import Data.Word type RGB = (Word8, Word8, Word8) ppmWrite :: A.Matrix RGB -> FilePath -> IO () ppmWrite img fp = do let A.Z A.:. h A.:. w = A.arrayShape img line y = unwords $ concat [[show r, show g, show b] | x <- [0 .. w - 1], let (r, g, b) = A.indexArray img (A.Z A.:. y A.:. x)] contents = unlines $ ["P3" ,show w ++ " " ++ show h ,"255"] ++ [line y | y <- [0 .. h - 1]] writeFile fp contents