%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} module Graphics.HDemo.Texture ( Texture(..), ColorLayer, size, pixels, pixelData, colorLayer ) where \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} import Data.Array.Diff( DiffUArray, indices, (!), bounds, array ) import Data.Word( Word8 ) \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} type ColorLayer = DiffUArray (Int, Int) Word8 \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} colorLayer :: Int -> Int -> [((Int,Int), Word8)] -> ColorLayer colorLayer w h = array ((0,0),(w-1,h-1)) \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} data Texture = Tex { rlayer :: ColorLayer , glayer :: ColorLayer , blayer :: ColorLayer } \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} pixels :: Texture -> [(Word8, Word8, Word8)] pixels (Tex lr lg lb) = [(lr!i,lg!i,lb!i) | i <- indices lr ] \end{code} \begin{code} pixelData :: Texture -> [Word8] pixelData (Tex lr lg lb) = concat [[lr!i,lg!i,lb!i] | i <- indices lr ] \end{code} \begin{code} size :: Texture -> (Int,Int) size (Tex lr _ _) = (maxw + 1,maxh + 1) where (_,(maxw,maxh)) = bounds lr \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%