Last active
December 27, 2015 09:39
-
-
Save bryant/7305681 to your computer and use it in GitHub Desktop.
converts raw grayscale values into pgm format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (intercalate) | |
import System.Environment (getArgs) | |
main = do | |
raw <- readFile =<< head `fmap` getArgs | |
putStrLn $ "P2 160 120 256\n" ++ rawToPGM raw | |
where | |
chunk width [] = [] | |
chunk width xs = a : chunk width b | |
where (a, b) = splitAt width xs | |
rawToPGM = unlines . joinCols . (chunk 160) . decimaled | |
decimaled = map (show . (read :: String -> Int)) . lines | |
joinCols = map $ intercalate " " |
glguy
commented
Nov 4, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment