summaryrefslogtreecommitdiff
path: root/test/Examples/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'test/Examples/Utils')
-rw-r--r--test/Examples/Utils/PPM.hs18
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