aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Processors.hs
diff options
context:
space:
mode:
authorpacien2019-12-31 00:16:29 +0100
committerpacien2019-12-31 00:16:29 +0100
commit9d2b6cf4641cfff08ad556d3a7b24d4d63464eb5 (patch)
tree374b88146cb32ea2b5ab8e8b7d613d16d65f0059 /compiler/src/Processors.hs
parentd0962ef2dea7e8a0c25ca8fdbc55fcbafeeb2f79 (diff)
downloadldgallery-9d2b6cf4641cfff08ad556d3a7b24d4d63464eb5.tar.gz
compiler: populate the properties field in the index
GitHub: closes #8
Diffstat (limited to 'compiler/src/Processors.hs')
-rw-r--r--compiler/src/Processors.hs32
1 files changed, 18 insertions, 14 deletions
diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs
index df05c24..dab9aaa 100644
--- a/compiler/src/Processors.hs
+++ b/compiler/src/Processors.hs
@@ -45,6 +45,9 @@ import Codec.Picture
45import Codec.Picture.Extra -- TODO: compare DCT and bilinear (and Lanczos, but it's not implemented) 45import Codec.Picture.Extra -- TODO: compare DCT and bilinear (and Lanczos, but it's not implemented)
46 46
47import Resource 47import Resource
48 ( DirProcessor, ItemProcessor, ThumbnailProcessor
49 , GalleryItemProps(..), Resolution(..) )
50
48import Files 51import Files
49 52
50 53
@@ -54,7 +57,7 @@ instance Exception ProcessingException
54data Format = 57data 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
57 | Other 60 | Unknown
58 61
59formatFromPath :: Path -> Format 62formatFromPath :: Path -> Format
60formatFromPath = aux . (map toLower) . takeExtension . fileName 63formatFromPath = aux . (map toLower) . takeExtension . fileName
@@ -66,7 +69,7 @@ formatFromPath = aux . (map toLower) . takeExtension . fileName
66 aux ".tiff" = Tiff 69 aux ".tiff" = Tiff
67 aux ".hdr" = Hdr 70 aux ".hdr" = Hdr
68 aux ".gif" = Gif 71 aux ".gif" = Gif
69 aux _ = Other 72 aux _ = Unknown
70 73
71 74
72type FileProcessor = 75type FileProcessor =
@@ -163,22 +166,23 @@ type ItemFileProcessor =
163 166
164itemFileProcessor :: Maybe Resolution -> Cache -> ItemFileProcessor 167itemFileProcessor :: Maybe Resolution -> Cache -> ItemFileProcessor
165itemFileProcessor maxRes cached inputBase outputBase resClass inputRes = 168itemFileProcessor maxRes cached inputBase outputBase resClass inputRes =
166 cached (processor maxRes (formatFromPath inputRes)) inPath outPath 169 cached processor inPath outPath
167 >> return relOutPath 170 >> return (relOutPath, props)
168 where 171 where
169 relOutPath = resClass /> inputRes 172 relOutPath = resClass /> inputRes
170 inPath = localPath $ inputBase /> inputRes 173 inPath = localPath $ inputBase /> inputRes
171 outPath = localPath $ outputBase /> relOutPath 174 outPath = localPath $ outputBase /> relOutPath
172 175 (processor, props) = formatProcessor maxRes $ formatFromPath inputRes
173 processor :: Maybe Resolution -> Format -> FileProcessor 176
174 processor Nothing _ = copyFileProcessor 177 formatProcessor :: Maybe Resolution -> Format -> (FileProcessor, GalleryItemProps)
175 processor (Just maxRes) Bmp = resizeStaticImageUpTo Bmp maxRes 178 formatProcessor Nothing _ = (copyFileProcessor, Other)
176 processor (Just maxRes) Jpg = resizeStaticImageUpTo Jpg maxRes 179 formatProcessor (Just maxRes) Bmp = (resizeStaticImageUpTo Bmp maxRes, Picture)
177 processor (Just maxRes) Png = resizeStaticImageUpTo Png maxRes 180 formatProcessor (Just maxRes) Jpg = (resizeStaticImageUpTo Jpg maxRes, Picture)
178 processor (Just maxRes) Tiff = resizeStaticImageUpTo Tiff maxRes 181 formatProcessor (Just maxRes) Png = (resizeStaticImageUpTo Png maxRes, Picture)
179 processor (Just maxRes) Hdr = resizeStaticImageUpTo Hdr maxRes 182 formatProcessor (Just maxRes) Tiff = (resizeStaticImageUpTo Tiff maxRes, Picture)
180 processor _ Gif = copyFileProcessor -- TODO: handle animated gif resizing 183 formatProcessor (Just maxRes) Hdr = (resizeStaticImageUpTo Hdr maxRes, Picture)
181 processor _ Other = copyFileProcessor -- TODO: handle video reencoding and others? 184 formatProcessor _ Gif = (copyFileProcessor, Other) -- TODO: handle animated gif resizing
185 formatProcessor _ Unknown = (copyFileProcessor, Other) -- TODO: handle video reencoding and others?
182 186
183 187
184type ThumbnailFileProcessor = 188type ThumbnailFileProcessor =