Permalink
Browse files

D.Z.Texture: new module

Add zoom-cache dependency, and ZoomReadable instance for TextureSlice
  • Loading branch information...
kfish committed Nov 23, 2011
1 parent 3a3120e commit 3b0734e730d8feef4bc51c15478d9572e65301b0
Showing with 100 additions and 2 deletions.
  1. +91 −0 Data/ZoomCache/Texture.hs
  2. +9 −2 texture-synthesis.cabal
View
@@ -0,0 +1,91 @@
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# OPTIONS -Wall #-}
+----------------------------------------------------------------------
+{- |
+ Module : Data.ZoomCache.Texture
+ Copyright : Conrad Parker
+ License : BSD3-style (see LICENSE)
+
+ Maintainer : Conrad Parker <conrad@metadecks.org>
+ Stability : unstable
+ Portability : unknown
+
+Zoom-cache codec implementation for textures, defined here as timeslices
+of type [Float].
+
+The table below describes the encoding of SummaryData for TextureSlice:
+
+@
+ | ... | -35
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Row 1 mean (float) | 36-39
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Row 2 mean (float) | 40-43
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Row 3 mean (float) | 44-47
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Row 4 mean (float) | 48-51
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ... | 52-
+@
+
+Field encoding formats:
+
+ @float@: big-endian IEEE 754-2008 binary32 (IEEE 754-1985 single)
+
+-}
+----------------------------------------------------------------------
+
+module Data.ZoomCache.Texture (
+) where
+
+import Control.Applicative ((<$>))
+import Control.Monad (replicateM)
+import Data.ByteString (ByteString)
+import Data.Iteratee (Iteratee)
+import Data.Typeable
+import Data.ZoomCache.Codec
+
+----------------------------------------------------------------------
+
+textureLength :: Int
+textureLength = 8
+
+----------------------------------------------------------------------
+
+data TextureSlice = TextureSlice [Float]
+ deriving (Show, Typeable)
+
+----------------------------------------------------------------------
+
+-- Identifier for track headers
+trackTypeTexture :: ByteString
+trackTypeTexture = "ZTEXf32b"
+
+----------------------------------------------------------------------
+-- Read
+
+instance ZoomReadable TextureSlice where
+ data SummaryData TextureSlice = SummaryTextureSlice
+ { summaryAvgs :: [Float]
+ }
+
+ trackIdentifier = const trackTypeTexture
+
+ readRaw = TextureSlice <$> readSlice
+ readSummary = SummaryTextureSlice <$> readSlice
+
+ prettyRaw = prettyPacketTexture
+ prettySummaryData = prettySummaryTexture
+
+readSlice :: (Functor m, Monad m) => Iteratee ByteString m [Float]
+readSlice = replicateM textureLength readFloat32be
+
+prettyPacketTexture :: TextureSlice -> String
+prettyPacketTexture = show
+
+prettySummaryTexture :: SummaryData TextureSlice -> String
+prettySummaryTexture SummaryTextureSlice{..} = show summaryAvgs
View
@@ -31,13 +31,17 @@ Library
base < 3
Exposed-modules:
+ Data.ZoomCache.Texture,
Graphics.TextureSynthesis
Build-depends:
+ bytestring >= 0.9 && < 0.10,
containers >= 0.2 && < 0.5,
+ iteratee >= 0.8.6.0 && < 0.9,
mwc-random,
parallel,
- primitive
+ primitive,
+ zoom-cache >= 0.8.0.0 && < 0.9
-- Modules not exported by this package.
-- Other-modules:
@@ -57,10 +61,13 @@ Executable texture-synthesis
base < 3
Build-Depends:
+ bytestring >= 0.9 && < 0.10,
containers >= 0.2 && < 0.5,
+ iteratee >= 0.8.6.0 && < 0.9,
mwc-random,
parallel,
- primitive
+ primitive,
+ zoom-cache >= 0.8.0.0 && < 0.9
Test-suite tests
Type: exitcode-stdio-1.0

0 comments on commit 3b0734e

Please sign in to comment.