From c0118f29bcfc1fb7cf61da7260e4fdc2283be241 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 30 Jan 2019 01:14:24 +0000 Subject: Fix ordering of PFM and add PPM --- app/Main.hs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'app/Main.hs') diff --git a/app/Main.hs b/app/Main.hs index 9c75d6f..d04a3b3 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,12 +1,26 @@ module Main where +import Criterion import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import qualified Data.Text as T +import Data.Word (Word8) import PFM +clamp :: PFMColour -> PPMColour +clamp (PFMColour ri gi bi) = + PPMColour (f ri) (f gi) (f bi) + where + v s = s * 255.0 + f s = if v s > 255.0 then 255 else fromInteger (round (v s)) +clamp _ = undefined + +clampImage :: PFMImage -> PPMImage +clampImage (PFMImage w h c) = + PPMImage w h . reverse $ fmap clamp <$> c + main :: IO () main = do - s <- B.readFile "/home/yannherklotz/Imperial/AdvancedGraphics/coursework1/CO417-Assignment1/UrbanProbe/urbanEM_latlong.pfm" - let i = parse s - BL.writeFile "random.pfm" $ encode i + -- s <- B.readFile "/home/yannherklotz/Imperial/AdvancedGraphics/coursework1/CO417-Assignment1/UrbanProbe/urbanEM_latlong.pfm" + s <- B.readFile "/home/yannherklotz/Downloads/memorial.pfm" + BL.writeFile "random.ppm" . encodePPM . clampImage . parse $ s -- cgit