netpbm 0.1.0 → 0.2.0
raw patch · 2 files changed
+37/−1 lines, 2 filesdep +storable-recordPVP ok
version bump matches the API change (PVP)
Dependencies added: storable-record
API changes (from Hackage documentation)
+ Graphics.Netpbm: PpmPixelDataRGB16 :: (Vector PpmPixelRGB16) -> PpmPixelData
+ Graphics.Netpbm: PpmPixelDataRGB8 :: (Vector PpmPixelRGB8) -> PpmPixelData
+ Graphics.Netpbm: data PpmPixelData
+ Graphics.Netpbm: instance Storable PpmPixelRGB16
+ Graphics.Netpbm: instance Storable PpmPixelRGB8
Files
- netpbm.cabal +2/−1
- src/Graphics/Netpbm.hs +35/−0
netpbm.cabal view
@@ -1,5 +1,5 @@ name: netpbm-version: 0.1.0+version: 0.2.0 license: MIT copyright: 2013 Niklas Hambüchen <mail@nh2.me> author: Niklas Hambüchen <mail@nh2.me>@@ -28,6 +28,7 @@ , attoparsec >= 0.10 , attoparsec-binary >= 0.2 , bytestring >= 0.10+ , storable-record >= 0.0.2.5 , unordered-containers >= 0.1.3.0 , vector >= 0.7 , vector-th-unbox >= 0.2.0.1
src/Graphics/Netpbm.hs view
@@ -13,6 +13,7 @@ , PPM (..) , PpmPixelRGB8 , PpmPixelRGB16+, PpmPixelData (..) , parsePPM , PpmParseResult -- TODO expose attoparsec functions in .Internal package@@ -27,6 +28,8 @@ import Data.Char (ord) import Data.List (foldl') import Data.Word (Word8, Word16)+import Foreign.Storable.Record as Store+import Foreign.Storable (Storable (..)) import qualified Data.Vector.Unboxed as U import qualified Data.Vector.Generic@@ -77,6 +80,8 @@ | PpmPixelDataRGB16 (U.Vector PpmPixelRGB16) -- ^ For 16-bit PPMs. +-- * Unbox instance for pixels+ derivingUnbox "PpmPixelRGB8" [t| PpmPixelRGB8 -> (Word8, Word8, Word8) |] [| \ (PpmPixelRGB8 a b c) -> (a, b, c) |]@@ -88,6 +93,35 @@ [| \ (a, b, c) -> PpmPixelRGB16 a b c |] +-- * Storable instance for pixels++storePixel8 :: Store.Dictionary PpmPixelRGB8+storePixel8 =+ Store.run $ liftA3 PpmPixelRGB8+ (Store.element (\(PpmPixelRGB8 x _ _) -> x))+ (Store.element (\(PpmPixelRGB8 _ y _) -> y))+ (Store.element (\(PpmPixelRGB8 _ _ z) -> z))++storePixel16 :: Store.Dictionary PpmPixelRGB16+storePixel16 =+ Store.run $ liftA3 PpmPixelRGB16+ (Store.element (\(PpmPixelRGB16 x _ _) -> x))+ (Store.element (\(PpmPixelRGB16 _ y _) -> y))+ (Store.element (\(PpmPixelRGB16 _ _ z) -> z))++instance Storable PpmPixelRGB8 where+ sizeOf = Store.sizeOf storePixel8+ alignment = Store.alignment storePixel8+ peek = Store.peek storePixel8+ poke = Store.poke storePixel8++instance Storable PpmPixelRGB16 where+ sizeOf = Store.sizeOf storePixel16+ alignment = Store.alignment storePixel16+ peek = Store.peek storePixel16+ poke = Store.poke storePixel16++ -- | Parses a netpbm magic number. -- One of P1, P2, P3, P4, P5, P6. magicNumberParser :: Parser PPMType@@ -195,3 +229,4 @@ Done "" images -> Right (images, Nothing) Done rest images -> Right (images, Just rest) Partial _ -> error "parsePPM bug: Got a partial result after end of input"+ Fail _ _ e -> Left e