blob: fe8751de389a3fb94caca3437659bd9bd07b593f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
|