diff options
Diffstat (limited to 'compiler/src/Processors.hs')
-rw-r--r-- | compiler/src/Processors.hs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs index 7bf1e36..67f8619 100644 --- a/compiler/src/Processors.hs +++ b/compiler/src/Processors.hs | |||
@@ -32,7 +32,7 @@ module Processors | |||
32 | ) where | 32 | ) where |
33 | 33 | ||
34 | 34 | ||
35 | import Control.Exception (throwIO) | 35 | import Control.Exception (Exception, throwIO) |
36 | import Data.Function ((&)) | 36 | import Data.Function ((&)) |
37 | import Data.Ratio ((%)) | 37 | import Data.Ratio ((%)) |
38 | import Data.Char (toLower) | 38 | import Data.Char (toLower) |
@@ -51,6 +51,9 @@ import Resource | |||
51 | import Files | 51 | import Files |
52 | 52 | ||
53 | 53 | ||
54 | data ProcessingException = ProcessingException FilePath String deriving Show | ||
55 | instance Exception ProcessingException | ||
56 | |||
54 | data Format = | 57 | data Format = |
55 | Bmp | Jpg | Png | Tiff | Hdr -- static images | 58 | Bmp | Jpg | Png | Tiff | Hdr -- static images |
56 | | Gif -- TODO: might be animated | 59 | | Gif -- TODO: might be animated |
@@ -82,14 +85,6 @@ copyFileProcessor inputPath outputPath = | |||
82 | (putStrLn $ "Copying:\t" ++ outputPath) | 85 | (putStrLn $ "Copying:\t" ++ outputPath) |
83 | >> ensureParentDir (flip System.Directory.copyFile) outputPath inputPath | 86 | >> ensureParentDir (flip System.Directory.copyFile) outputPath inputPath |
84 | 87 | ||
85 | eitherIOToIO :: Either String (IO a) -> IO a | ||
86 | eitherIOToIO (Left err) = throwIO $ userError err | ||
87 | eitherIOToIO (Right res) = res | ||
88 | |||
89 | eitherResToIO :: Either String a -> IO a | ||
90 | eitherResToIO (Left err) = throwIO $ userError err | ||
91 | eitherResToIO (Right res) = return res | ||
92 | |||
93 | resizeStaticImageUpTo :: Format -> Resolution -> FileProcessor | 88 | resizeStaticImageUpTo :: Format -> Resolution -> FileProcessor |
94 | resizeStaticImageUpTo Bmp = resizeStaticGeneric readBitmap saveBmpImage | 89 | resizeStaticImageUpTo Bmp = resizeStaticGeneric readBitmap saveBmpImage |
95 | -- TODO: parameterise export quality for jpg | 90 | -- TODO: parameterise export quality for jpg |
@@ -97,7 +92,12 @@ resizeStaticImageUpTo Jpg = resizeStaticGeneric readJpeg (saveJpgImage 80) | |||
97 | resizeStaticImageUpTo Png = resizeStaticGeneric readPng savePngImage | 92 | resizeStaticImageUpTo Png = resizeStaticGeneric readPng savePngImage |
98 | resizeStaticImageUpTo Tiff = resizeStaticGeneric readTiff saveTiffImage | 93 | resizeStaticImageUpTo Tiff = resizeStaticGeneric readTiff saveTiffImage |
99 | resizeStaticImageUpTo Hdr = resizeStaticGeneric readHDR saveRadianceImage | 94 | resizeStaticImageUpTo Hdr = resizeStaticGeneric readHDR saveRadianceImage |
100 | resizeStaticImageUpTo Gif = resizeStaticGeneric readGif ((.) eitherIOToIO . saveGifImage) | 95 | resizeStaticImageUpTo Gif = resizeStaticGeneric readGif writeGifImage |
96 | where | ||
97 | writeGifImage :: StaticImageWriter | ||
98 | writeGifImage outputPath image = | ||
99 | saveGifImage outputPath image | ||
100 | & either (throwIO . ProcessingException outputPath) id | ||
101 | 101 | ||
102 | 102 | ||
103 | type StaticImageReader = FilePath -> IO (Either String DynamicImage) | 103 | type StaticImageReader = FilePath -> IO (Either String DynamicImage) |
@@ -107,7 +107,7 @@ resizeStaticGeneric :: StaticImageReader -> StaticImageWriter -> Resolution -> F | |||
107 | resizeStaticGeneric reader writer maxRes inputPath outputPath = | 107 | resizeStaticGeneric reader writer maxRes inputPath outputPath = |
108 | (putStrLn $ "Generating:\t" ++ outputPath) | 108 | (putStrLn $ "Generating:\t" ++ outputPath) |
109 | >> reader inputPath | 109 | >> reader inputPath |
110 | >>= eitherResToIO | 110 | >>= either (throwIO . ProcessingException inputPath) return |
111 | >>= return . (fitDynamicImage maxRes) | 111 | >>= return . (fitDynamicImage maxRes) |
112 | >>= ensureParentDir writer outputPath | 112 | >>= ensureParentDir writer outputPath |
113 | 113 | ||