@@ -158,7 +158,7 @@ jpegSize img =
158158 then Left "unable to determine JPEG size"
159159 else case hdr of
160160 "\xff\xd8\xff\xe0" -> jfifSize rest
161− "\xff\xd8\xff\xe1" -> exifSize $ B.takeWhile (/= '\xff') rest
161+ "\xff\xd8\xff\xe1" -> exifSize rest
162162 _ -> Left "unable to determine JPEG size"
163163
164164jfifSize :: ByteString -> Either String ImageSize
@@ -249,29 +249,33 @@ exifHeader hdr = do
249249 numComponents <- lift getWord32
250250 (fmt, bytesPerComponent) <-
251251 case dataFormat of
252− 1 -> return (UnsignedByte . runGet getWord8, 1)
253− 2 -> return (AsciiString, 1)
254− 3 -> return (UnsignedShort . runGet getWord16, 2)
255− 4 -> return (UnsignedLong . runGet getWord32, 4)
256− 5 -> return (UnsignedRational . runGet getRational, 8)
257− 6 -> return (SignedByte . runGet getWord8, 1)
258− 7 -> return (Undefined . runGet getWord8, 1)
259− 8 -> return (SignedShort . runGet getWord16, 2)
260− 9 -> return (SignedLong . runGet getWord32, 4)
261− 10 -> return (SignedRational . runGet getRational, 8)
262− 11 -> return (SingleFloat . runGet getWord32 {- TODO -}, 4)
263− 12 -> return (DoubleFloat . runGet getWord64 {- TODO -}, 8)
252+ 1 -> return (UnsignedByte <$> getWord8, 1)
253+ 2 -> return (AsciiString <$>
254+ getLazyByteString
255+ (fromIntegral numComponents), 1)
256+ 3 -> return (UnsignedShort <$> getWord16, 2)
257+ 4 -> return (UnsignedLong <$> getWord32, 4)
258+ 5 -> return (UnsignedRational <$> getRational, 8)
259+ 6 -> return (SignedByte <$> getWord8, 1)
260+ 7 -> return (Undefined <$> getLazyByteString
261+ (fromIntegral numComponents), 1)
262+ 8 -> return (SignedShort <$> getWord16, 2)
263+ 9 -> return (SignedLong <$> getWord32, 4)
264+ 10 -> return (SignedRational <$> getRational, 8)
265+ 11 -> return (SingleFloat <$> getWord32 {- TODO -}, 4)
266+ 12 -> return (DoubleFloat <$> getWord64 {- TODO -}, 8)
264267 _ -> throwError $ "Unknown data format " ++ show dataFormat
265268 let totalBytes = fromIntegral $ numComponents * bytesPerComponent
266− payload <- lift $
267− if totalBytes <= 4 -- data is right here
268− then fmt <$>
269− (getLazyByteString (fromIntegral totalBytes) <*
270− skip (4 - totalBytes))
269+ payload <- if totalBytes <= 4 -- data is right here
270+ then lift $ fmt <* skip (4 - totalBytes)
271271 else do -- get data from offset
272− offs <- getWord32
273− return $ fmt $ BL.take (fromIntegral totalBytes) $
274− BL.drop (fromIntegral offs) tiffHeader
272+ offs <- lift getWord32
273+ let bytesAtOffset =
274+ BL.take (fromIntegral totalBytes)
275+ $ BL.drop (fromIntegral offs) tiffHeader
276+ case runGet' (Right <$> fmt) bytesAtOffset of
277+ Left msg -> throwError msg
278+ Right x -> return x
275279 return (tag, payload)
276280 entries <- sequence $ replicate (fromIntegral numentries) ifdEntry
277281 subentries <- case lookup ExifOffset entries of
@@ -309,7 +313,7 @@ data DataFormat = UnsignedByte Word8
309313 | UnsignedLong Word32
310314 | UnsignedRational Rational
311315 | SignedByte Word8
312− | Undefined Word8
316+ | Undefined BL.ByteString
313317 | SignedShort Word16
314318 | SignedLong Word32
315319 | SignedRational Rational