From 1640830bf5dc0630481e698512064215eb3e8249 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 10 Oct 2021 19:55:59 +0200 Subject: WIP --- test/Examples/Utils/PPM.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/Examples/Utils/PPM.hs (limited to 'test/Examples/Utils') diff --git a/test/Examples/Utils/PPM.hs b/test/Examples/Utils/PPM.hs new file mode 100644 index 0000000..fe8751d --- /dev/null +++ b/test/Examples/Utils/PPM.hs @@ -0,0 +1,18 @@ +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 -- cgit v1.2.3-70-g09d2