1 -- Copyright (c) 2000 Galois Connections, Inc.
2 -- All rights reserved. This software is distributed as
3 -- free software under the license in the file "LICENSE",
4 -- which is included in the distribution.
13 = do h <- openFile f ReadMode
15 case (parse parsePPM f s) of
16 Left err -> error (show err)
20 = do h <- openFile f WriteMode
21 let s = showPPM (length (head ppm)) (length ppm) ppm
36 return (chop width (chopColors cs))
39 chopColors (a:b:c:ds) = (ord a, ord b, ord c) : chopColors ds
42 chop n xs = h : chop n t
43 where (h, t) = splitAt n xs
46 = do ds <- many1 digit
47 return (read ds :: Int)
50 = skipMany (simpleSpace <|> oneLineComment <?> "")
51 where simpleSpace = skipMany1 (oneOf " \t\n\r\v")
54 skipMany (noneOf "\n\r\v")
59 showPPM :: Int -> Int -> [[(Int,Int,Int)]] -> String
61 = header ++ concat [[chr r, chr g, chr b] | ps <- pss, (r, g, b) <-ps]
63 header = "P6\n#Galois\n" ++ show wid ++ " " ++ show ht ++ "\n255\n"
64 showPPM _ _ _ = error "incorrect length of bitmap string"