diff options
author | pacien | 2019-12-31 00:16:29 +0100 |
---|---|---|
committer | pacien | 2019-12-31 00:16:29 +0100 |
commit | 9d2b6cf4641cfff08ad556d3a7b24d4d63464eb5 (patch) | |
tree | 374b88146cb32ea2b5ab8e8b7d613d16d65f0059 /compiler/src/Processors.hs | |
parent | d0962ef2dea7e8a0c25ca8fdbc55fcbafeeb2f79 (diff) | |
download | ldgallery-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.hs | 32 |
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 | |||
45 | import Codec.Picture.Extra -- TODO: compare DCT and bilinear (and Lanczos, but it's not implemented) | 45 | import Codec.Picture.Extra -- TODO: compare DCT and bilinear (and Lanczos, but it's not implemented) |
46 | 46 | ||
47 | import Resource | 47 | import Resource |
48 | ( DirProcessor, ItemProcessor, ThumbnailProcessor | ||
49 | , GalleryItemProps(..), Resolution(..) ) | ||
50 | |||
48 | import Files | 51 | import Files |
49 | 52 | ||
50 | 53 | ||
@@ -54,7 +57,7 @@ instance Exception ProcessingException | |||
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 |
57 | | Other | 60 | | Unknown |
58 | 61 | ||
59 | formatFromPath :: Path -> Format | 62 | formatFromPath :: Path -> Format |
60 | formatFromPath = aux . (map toLower) . takeExtension . fileName | 63 | formatFromPath = 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 | ||
72 | type FileProcessor = | 75 | type FileProcessor = |
@@ -163,22 +166,23 @@ type ItemFileProcessor = | |||
163 | 166 | ||
164 | itemFileProcessor :: Maybe Resolution -> Cache -> ItemFileProcessor | 167 | itemFileProcessor :: Maybe Resolution -> Cache -> ItemFileProcessor |
165 | itemFileProcessor maxRes cached inputBase outputBase resClass inputRes = | 168 | itemFileProcessor 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 | ||
184 | type ThumbnailFileProcessor = | 188 | type ThumbnailFileProcessor = |