packages feed

hsexif 0.5.0.0 → 0.5.0.1

raw patch · 3 files changed

+27/−4 lines, 3 filesdep ~hspecPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependency ranges changed: hspec

API changes (from Hackage documentation)

+ Graphics.HsExif: formatAsFloatingPoint :: Int -> ExifValue -> String

Files

Graphics/HsExif.hs view
@@ -14,6 +14,7 @@ 	ImageOrientation(..), 	RotationDirection(..), 	getGpsLatitudeLongitude,+	formatAsFloatingPoint,  	-- * The ExifValue type 	ExifValue(..),@@ -154,6 +155,7 @@ import Data.Time.LocalTime import Data.Time.Calendar import Numeric (showHex)+import Text.Printf  -- | An exif value. -- @@ -765,12 +767,27 @@ 	return (signedLatDec, signedLongDec)  gpsDecodeToDecimalDegrees :: ExifValue -> Maybe Double-gpsDecodeToDecimalDegrees (ExifRationalList intPairs) = case fmap (uncurry intsToFloating) intPairs of+gpsDecodeToDecimalDegrees (ExifRationalList intPairs) = case fmap intPairToFloating intPairs of 			(degrees:minutes:seconds:[]) -> Just $ degrees + minutes / 60 + seconds / 3600 			_ -> Nothing 	where-		intsToFloating n d = fromIntegral n / fromIntegral d+		intPairToFloating (n, d) = fromIntegral n / fromIntegral d gpsDecodeToDecimalDegrees _ = Nothing++-- | Format the exif value as floating-point if it makes sense,+-- otherwise use the default 'show' implementation.+-- The first parameter lets you specify how many digits after+-- the comma to format in the result string.+-- The special behaviour applies only for 'ExifRational' and 'ExifRationalList'.+formatAsFloatingPoint :: Int -> ExifValue -> String+formatAsFloatingPoint n (ExifRational num den) = formatNumDenAsString n num den+formatAsFloatingPoint n (ExifRationalList values) = intercalate ", " $ foldl' step [] values+	where step soFar (num,den) = soFar ++ [formatNumDenAsString n num den]+formatAsFloatingPoint _ v = show v++formatNumDenAsString :: Int -> Int -> Int -> String+formatNumDenAsString n num den = printf formatString (fromIntegral num / fromIntegral den :: Double)+	where formatString = "%." ++ show n ++ "f"  -- $intro --
hsexif.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                hsexif-version:             0.5.0.0+version:             0.5.0.1 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.@@ -36,7 +36,7 @@   main-is: Tests.hs   default-language:    Haskell2010   build-depends:       base,-                       hspec >= 1.8 && <1.9,+                       hspec == 1.10.*,                        HUnit >= 1.2 && <1.3,                        binary >=0.7 && <0.8,                        bytestring >=0.10 && <0.11,
tests/Tests.hs view
@@ -29,6 +29,7 @@ 		describe "read exif date time" testReadExifDateTime 		describe "read GPS lat long" $ testReadGpsLatLong gpsExifData 		describe "read GPS lat long -- no data" $ testReadGpsLatLongNoData exifData+		describe "test formatAsFloatingPoint" $ testFormatAsFloatingPoint  testNotAJpeg :: B.ByteString -> Spec testNotAJpeg imageContents = it "returns empty list if not a JPEG" $@@ -121,6 +122,11 @@ testReadGpsLatLongNoData :: Map ExifTag ExifValue -> Spec testReadGpsLatLongNoData exifData = it "reads gps latitude longitude" $ 	assertEqual' Nothing $ getGpsLatitudeLongitude exifData++testFormatAsFloatingPoint :: Spec+testFormatAsFloatingPoint = it "properly formats as floating point" $ do+	assertEqual' "0.75" $ formatAsFloatingPoint 2 $ ExifRational 3 4+	assertEqual' "0.75, -0.50, 0.25" $ formatAsFloatingPoint 2 $ ExifRationalList [(3,4),(-1,2),(1,4)]  assertEqual' :: (Show a, Eq a) => a -> a -> Assertion assertEqual' = assertEqual "doesn't match"