@@ -120,7 +120,7 @@ imageType img = case B.take 4 img of
120120 | findSvgTag img
121121 -> return Svg
122122 "%!PS"
123− | (B.take 4 $ B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF"
123+ | B.take 4 (B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF"
124124 -> return Eps
125125 _ -> mzero
126126
@@ -168,7 +168,7 @@ desiredSizeInPoints opts attr s =
168168 (Nothing, Nothing) -> sizeInPoints s
169169 where
170170 ratio = fromIntegral (pxX s) / fromIntegral (pxY s)
171− getDim dir = case (dimension dir attr) of
171+ getDim dir = case dimension dir attr of
172172 Just (Percent _) -> Nothing
173173 Just dim -> Just $ inPoints opts dim
174174 Nothing -> Nothing
@@ -182,7 +182,7 @@ inEm opts dim = (64/11) * inInch opts dim
182182inInch :: WriterOptions -> Dimension -> Double
183183inInch opts dim =
184184 case dim of
185− (Pixel a) -> fromIntegral a / (fromIntegral $ writerDpi opts)
185+ (Pixel a) -> fromIntegral a / fromIntegral (writerDpi opts)
186186 (Centimeter a) -> a * 0.3937007874
187187 (Inch a) -> a
188188 (Percent _) -> 0
@@ -261,7 +261,7 @@ epsSize img = do
261261 case ls' of
262262 [] -> mzero
263263 (x:_) -> case B.words x of
264− (_:_:_:ux:uy:[]) -> do
264+ [_, _, _, ux, uy] -> do
265265 ux' <- safeRead $ B.unpack ux
266266 uy' <- safeRead $ B.unpack uy
267267 return ImageSize{
@@ -279,27 +279,26 @@ pngSize img = do
279279 let (i, rest') = B.splitAt 4 $ B.drop 4 rest
280280 guard $ i == "MHDR" || i == "IHDR"
281281 let (sizes, rest'') = B.splitAt 8 rest'
282− (x,y) <- case map fromIntegral $ unpack $ sizes of
282+ (x,y) <- case map fromIntegral $unpack sizes of
283283 ([w1,w2,w3,w4,h1,h2,h3,h4] :: [Integer]) -> return
284− ((shift w1 24) + (shift w2 16) + (shift w3 8) + w4,
285− (shift h1 24) + (shift h2 16) + (shift h3 8) + h4)
284+ (shift w1 24 + shift w2 16 + shift w3 8 + w4,
285+ shift h1 24 + shift h2 16 + shift h3 8 + h4)
286286 _ -> Nothing -- "PNG parse error"
287287 let (dpix, dpiy) = findpHYs rest''
288− return $ ImageSize { pxX = x, pxY = y, dpiX = dpix, dpiY = dpiy }
288+ return ImageSize { pxX = x, pxY = y, dpiX = dpix, dpiY = dpiy }
289289
290290findpHYs :: ByteString -> (Integer, Integer)
291−findpHYs x =
292− if B.null x || "IDAT" `B.isPrefixOf` x
293− then (72,72) -- default, no pHYs
294− else if "pHYs" `B.isPrefixOf` x
295− then let [x1,x2,x3,x4,y1,y2,y3,y4,u] = map fromIntegral
296− $ unpack $ B.take 9 $ B.drop 4 x
297− factor = if u == 1 -- dots per meter
298− then \z -> z * 254 `div` 10000
299− else const 72
300− in ( factor $ (shift x1 24) + (shift x2 16) + (shift x3 8) + x4,
301− factor $ (shift y1 24) + (shift y2 16) + (shift y3 8) + y4 )
302− else findpHYs $ B.drop 1 x -- read another byte
291+findpHYs x
292+ | B.null x || "IDAT" `B.isPrefixOf` x = (72,72)
293+ | "pHYs" `B.isPrefixOf` x =
294+ let [x1,x2,x3,x4,y1,y2,y3,y4,u] =
295+ map fromIntegral $ unpack $ B.take 9 $ B.drop 4 x
296+ factor = if u == 1 -- dots per meter
297+ then \z -> z * 254 `div` 10000
298+ else const 72
299+ in ( factor $ (shift x1 24) + (shift x2 16) + (shift x3 8) + x4,
300+ factor $ (shift y1 24) + (shift y2 16) + (shift y3 8) + y4 )
301+ | otherwise = findpHYs $ B.drop 1 x -- read another byte
303302
304303gifSize :: ByteString -> Maybe ImageSize
305304gifSize img = do
@@ -343,16 +342,16 @@ jpegSize img =
343342jfifSize :: ByteString -> Either String ImageSize
344343jfifSize rest =
345344 let [dpiDensity,dpix1,dpix2,dpiy1,dpiy2] = map fromIntegral
346− $ unpack $ B.take 5 $ B.drop 9 $ rest
345+ $ unpack $ B.take 5 $B.drop 9 rest
347346 factor = case dpiDensity of
348347 1 -> id
349− 2 -> \x -> (x * 254 `div` 10)
348+ 2 -> \x -> x * 254 `div` 10
350349 _ -> const 72
351350 dpix = factor (shift dpix1 8 + dpix2)
352351 dpiy = factor (shift dpiy1 8 + dpiy2)
353352 in case findJfifSize rest of
354353 Left msg -> Left msg
355− Right (w,h) -> Right $ ImageSize { pxX = w
354+ Right (w,h) ->Right ImageSize { pxX = w
356355 , pxY = h
357356 , dpiX = dpix
358357 , dpiY = dpiy }
@@ -386,7 +385,7 @@ runGet' p bl =
386385
387386
388387exifSize :: ByteString -> Either String ImageSize
389−exifSize bs = runGet' header $ bl
388+exifSize bs =runGet' header bl
390389 where bl = BL.fromChunks [bs]
391390 header = runExceptT $ exifHeader bl
392391-- NOTE: It would be nicer to do
@@ -456,14 +455,13 @@ exifHeader hdr = do
456455 Left msg -> throwError msg
457456 Right x -> return x
458457 return (tag, payload)
459− entries <- sequence $ replicate (fromIntegral numentries) ifdEntry
458+ entries <- replicateM (fromIntegral numentries) ifdEntry
460459 subentries <- case lookup ExifOffset entries of
461460 Just (UnsignedLong offset') -> do
462461 pos <- lift bytesRead
463462 lift $ skip (fromIntegral offset' - (fromIntegral pos - 8))
464463 numsubentries <- lift getWord16
465− sequence $
466− replicate (fromIntegral numsubentries) ifdEntry
464+ replicateM (fromIntegral numsubentries) ifdEntry
467465 _ -> return []
468466 let allentries = entries ++ subentries
469467 (wdth, hght) <- case (lookup ExifImageWidth allentries,
@@ -474,13 +472,13 @@ exifHeader hdr = do
474472 -- we return a default width and height when
475473 -- the exif header doesn't contain these
476474 let resfactor = case lookup ResolutionUnit allentries of
477− Just (UnsignedShort 1) -> (100 / 254)
475+ Just (UnsignedShort 1) -> 100 / 254
478476 _ -> 1
479477 let xres = maybe 72 (\(UnsignedRational x) -> floor $ x * resfactor)
480478 $ lookup XResolution allentries
481479 let yres = maybe 72 (\(UnsignedRational x) -> floor $ x * resfactor)
482480 $ lookup YResolution allentries
483− return $ ImageSize{
481+ return ImageSize{
484482 pxX = wdth
485483 , pxY = hght
486484 , dpiX = xres
@@ -604,3 +602,4 @@ tagTypeTable = M.fromList
604602 , (0xa300, FileSource)
605603 , (0xa301, SceneType)
606604 ]
605+