hsexif 0.6.0.4 → 0.6.0.5
raw patch · 4 files changed
+23/−10 lines, 4 filesbinary-addedPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Graphics/HsExif.hs +11/−1
- hsexif.cabal +1/−1
- tests/Tests.hs +11/−8
- tests/gps3.jpg binary
Graphics/HsExif.hs view
@@ -146,9 +146,11 @@ import Data.Binary.Get import Data.Binary.Put import qualified Data.ByteString.Lazy as B+import qualified Data.ByteString as BS import Control.Monad (liftM, unless, replicateM) import Control.Applicative ( (<$>) ) import qualified Data.ByteString.Char8 as Char8+import Data.ByteString.Internal (w2c) import Data.Word import Data.Char (ord) import Data.Int (Int32, Int16, Int8)@@ -300,6 +302,14 @@ readNumberList decoder byteAlign components = ExifNumberList . fmap fromIntegral <$> count components (decoder byteAlign) +decodeTextByteString :: BS.ByteString -> String+decodeTextByteString bs = w2c <$> strippedWords+ where+ strippedWords = if not (null bsWords) && last bsWords == 0+ then init bsWords+ else bsWords+ bsWords = BS.unpack bs+ unsignedByteValueHandler = ValueHandler { dataTypeId = 1,@@ -313,7 +323,7 @@ dataTypeId = 2, dataLength = 1, readSingle = \ba -> readMany asciiStringValueHandler ba 1,- readMany = \_ components -> ExifText . Char8.unpack <$> getByteString (components-1)+ readMany = \_ components -> ExifText . decodeTextByteString <$> getByteString components } unsignedShortValueHandler = ValueHandler
hsexif.cabal view
@@ -1,5 +1,5 @@ name: hsexif-version: 0.6.0.4+version: 0.6.0.5 synopsis: EXIF handling library in pure Haskell description: The hsexif library provides functions for working with EXIF data contained in JPEG files. Currently it only supports reading the data.
tests/Tests.hs view
@@ -24,11 +24,13 @@ png <- B.readFile "tests/test.png" gps <- B.readFile "tests/gps.jpg" gps2 <- B.readFile "tests/gps2.jpg"+ gps3 <- B.readFile "tests/gps3.jpg" partial <- B.readFile "tests/partial_exif.jpg" let parseExifM = hush . parseExif let exifData = parseExifM imageContents let gpsExifData = parseExifM gps let gps2ExifData = parseExifM gps2+ let gps3ExifData = parseExifM gps3 hspec $ do describe "not a JPG" $ testNotAJpeg png describe "no EXIF" $ testNoExif noExif@@ -36,8 +38,10 @@ describe "extract picture date" $ testDate exifData describe "image orientation" $ testOrientation exifData describe "read exif date time" testReadExifDateTime- describe "read GPS lat long" $ testReadGpsLatLong gpsExifData+ describe "read GPS lat long" $ testReadGpsLatLong gpsExifData 50.2179 (-5.031) describe "read GPS lat long -- no data" $ testReadGpsLatLongNoData exifData+ describe "read GPS lat long -- length 1 for rel" $+ testReadGpsLatLong gps3ExifData 38.1785 (-7.2109) describe "test formatAsFloatingPoint" testFormatAsFloatingPoint describe "pretty printing" $ testPrettyPrint gpsExifData exifData gps2ExifData describe "flash fired" $ testFlashFired exifData@@ -130,11 +134,13 @@ assertEqual' (Just $ LocalTime (fromGregorian 2013 10 2) (TimeOfDay 20 33 33)) (readExifDateTime "2013:10:02 20:33:33") assertEqual' Nothing (readExifDateTime "2013:10:02 20:33:3") -testReadGpsLatLong :: Maybe (Map ExifTag ExifValue) -> Spec-testReadGpsLatLong exifData = it "reads gps latitude longitude" $ do+testReadGpsLatLong :: Maybe (Map ExifTag ExifValue) -> Double -> Double -> Spec+testReadGpsLatLong exifData xLat xLong = it "reads gps latitude longitude" $ do let (Just (lat,long)) = exifData >>= getGpsLatitudeLongitude- assertBool' $ 50.2179 < lat && 50.2180 > lat- assertBool' $ -5.031 > long && -5.032 < long+ let equalEnough a b = assertBool (show a ++ " too different from " ++ show b ) $+ abs (a - b) < 0.001+ equalEnough lat xLat+ equalEnough long xLong testReadGpsLatLongNoData :: Maybe (Map ExifTag ExifValue) -> Spec testReadGpsLatLongNoData exifData = it "reads gps latitude longitude" $@@ -212,6 +218,3 @@ assertEqual' :: (Show a, Eq a) => a -> a -> Assertion assertEqual' = assertEqual "doesn't match"--assertBool' :: Bool -> Assertion-assertBool' = assertBool "doesn't match"
+ tests/gps3.jpg view
binary file changed (absent → 2425 bytes)