Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Iteratee: add enumTexture, enumSummaryTexture

  • Loading branch information...
commit e553c81b1ab6dfc03c7a252073611f4457a0cc02 1 parent b62a660
@kfish authored
Showing with 34 additions and 0 deletions.
  1. +32 −0 Data/ZoomCache/Texture.hs
  2. +2 −0  texture-synthesis.cabal
View
32 Data/ZoomCache/Texture.hs
@@ -45,6 +45,10 @@ module Data.ZoomCache.Texture (
-- * Types
TextureSlice(..)
+ -- * Iteratee reading of textures
+ , enumTexture
+ , enumSummaryTexture
+
-- * Zoom-cache codec instances
, SummaryData(..)
, SummaryWork(..)
@@ -56,10 +60,14 @@ module Data.ZoomCache.Texture (
import Blaze.ByteString.Builder
import Control.Applicative ((<$>))
import Control.Monad (replicateM)
+import Control.Monad.Trans (MonadIO)
import Data.ByteString (ByteString)
import Data.Iteratee (Iteratee)
+import qualified Data.Iteratee as I
+import Data.Maybe (catMaybes, fromMaybe)
import Data.Monoid (mconcat)
import Data.Typeable
+import Data.ZoomCache
import Data.ZoomCache.Codec
----------------------------------------------------------------------
@@ -175,3 +183,27 @@ appendSummaryTexture (TSDiff dur1) s1 (TSDiff dur2) s2 = SummaryTextureSlice {
dur1' = fromIntegral dur1
dur2' = fromIntegral dur2
durSum = fromIntegral (dur1 + dur2)
+
+----------------------------------------------------------------------
+
+rawToTexture :: ZoomRaw -> [TextureSlice]
+rawToTexture (ZoomRaw xs) | typeOf xs == typeOf (undefined :: [TextureSlice]) =
+ fromMaybe [] (cast xs :: Maybe [TextureSlice])
+ | otherwise = []
+
+enumTexture :: (Functor m, MonadIO m)
+ => I.Enumeratee [Stream] [(TimeStamp, TextureSlice)] m a
+enumTexture = I.joinI . enumPackets . I.mapChunks (concatMap f)
+ where
+ f :: Packet -> [(TimeStamp, TextureSlice)]
+ f Packet{..} = zip packetTimeStamps (rawToTexture packetData)
+
+enumSummaryTexture :: (Functor m, MonadIO m)
+ => Int
+ -> I.Enumeratee [Stream] [Summary TextureSlice] m a
+enumSummaryTexture level =
+ I.joinI . enumSummaryLevel level .
+ I.mapChunks (catMaybes . map toSD)
+ where
+ toSD :: ZoomSummary -> Maybe (Summary TextureSlice)
+ toSD (ZoomSummary s) = cast s
View
2  texture-synthesis.cabal
@@ -39,6 +39,7 @@ Library
bytestring >= 0.9 && < 0.10,
containers >= 0.2 && < 0.5,
iteratee >= 0.8.6.0 && < 0.9,
+ mtl >= 2.0.0.0 && < 3,
mwc-random,
parallel,
primitive,
@@ -66,6 +67,7 @@ Executable texture-synthesis
bytestring >= 0.9 && < 0.10,
containers >= 0.2 && < 0.5,
iteratee >= 0.8.6.0 && < 0.9,
+ mtl >= 2.0.0.0 && < 3,
mwc-random,
parallel,
primitive,
Please sign in to comment.
Something went wrong with that request. Please try again.