module ShowImage (showImage) where import ImageTypes -- ---------------------------------------- showImage :: Bool -> Image -> String showImage bin (Image (Geo w h) at) = imgType ++ imgGeo ++ "255\n" ++ imgData where imgGeo = show w ++ " " ++ show h ++ "\n# Haskell PPM Tools\n" imgType | bin = "P5\n" | otherwise = "P2\n" imgData = pixToChar . pixToList $ at pixToChar | bin = map toEnum | otherwise = concatMap ((++ "\n") . show) pixToList f = [ toPix (f x y) | y <- [0..h-1], x <- [0..w-1] ] where toPix :: Lightness -> Int toPix c = floor (c * 256.0) `min` 255 `max` 0 -- ----------------------------------------