diff options
author | Tom Smeding <tom@tomsmeding.com> | 2021-10-10 19:55:59 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2021-10-10 19:55:59 +0200 |
commit | 1640830bf5dc0630481e698512064215eb3e8249 (patch) | |
tree | 229b5666508e1152b5fff77733e48539591af0ab /test/Examples/Utils/PPM.hs | |
parent | ff220bfb4c4c67f666a4701f2514d8de432f1e9a (diff) |
Diffstat (limited to 'test/Examples/Utils/PPM.hs')
-rw-r--r-- | test/Examples/Utils/PPM.hs | 18 |
1 files changed, 18 insertions, 0 deletions
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 |