aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-08-10 15:13:19 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-08-10 15:13:19 -0700
commit7bc879268c1a86799a642280c296011e07e98c77 (patch)
treec10f0f7e75db4222fbbfc45708271a7942944baa /src/Text/Pandoc
parente055f1b21e0c9a4486850eac3a2dea12b7d74849 (diff)
downloadpandoc-7bc879268c1a86799a642280c296011e07e98c77.tar.gz
Avoid non-exhaustive pattern match.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/ImageSize.hs22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/Text/Pandoc/ImageSize.hs b/src/Text/Pandoc/ImageSize.hs
index c5fe98a66..00ab86eab 100644
--- a/src/Text/Pandoc/ImageSize.hs
+++ b/src/Text/Pandoc/ImageSize.hs
@@ -319,20 +319,22 @@ pngSize img = do
(shift w1 24 + shift w2 16 + shift w3 8 + w4,
shift h1 24 + shift h2 16 + shift h3 8 + h4)
_ -> Nothing -- "PNG parse error"
- let (dpix, dpiy) = findpHYs rest''
+ (dpix, dpiy) <- findpHYs rest''
return ImageSize { pxX = x, pxY = y, dpiX = dpix, dpiY = dpiy }
-findpHYs :: ByteString -> (Integer, Integer)
+findpHYs :: ByteString -> Maybe (Integer, Integer)
findpHYs x
- | B.null x || "IDAT" `B.isPrefixOf` x = (72,72)
+ | B.null x || "IDAT" `B.isPrefixOf` x = return (72,72)
| "pHYs" `B.isPrefixOf` x =
- let [x1,x2,x3,x4,y1,y2,y3,y4,u] =
- map fromIntegral $ unpack $ B.take 9 $ B.drop 4 x
- factor = if u == 1 -- dots per meter
- then \z -> z * 254 `div` 10000
- else const 72
- in ( factor $ shift x1 24 + shift x2 16 + shift x3 8 + x4,
- factor $ shift y1 24 + shift y2 16 + shift y3 8 + y4 )
+ case map fromIntegral $ unpack $ B.take 9 $ B.drop 4 x of
+ [x1,x2,x3,x4,y1,y2,y3,y4,u] -> do
+ let factor = if u == 1 -- dots per meter
+ then \z -> z * 254 `div` 10000
+ else const 72
+ return
+ ( factor $ shift x1 24 + shift x2 16 + shift x3 8 + x4,
+ factor $ shift y1 24 + shift y2 16 + shift y3 8 + y4 )
+ _ -> mzero
| otherwise = findpHYs $ B.drop 1 x -- read another byte
gifSize :: ByteString -> Maybe ImageSize