Hi Ben,
I had a stab at this, which is almost certainly wrong. Is it just
slightly wrong, or wrong because it is currently not possible?
--8<---------------cut here---------------start------------->8---
{-# LANGUAGE BangPatterns,LambdaCase #-}
module StencilGen where
import Data.Array.Repa hiding ((++),map)
import Data.Array.Repa.Stencil
mkStencil :: Array U DIM2 Int -> Stencil DIM2 Int
mkStencil !template = makeStencil (Z :. 3 :. 3) values
where
normalisePixel :: Int -> Maybe Int
normalisePixel i = if i == 0 then Nothing else Just i
values =
\case
Z :. -1 :. -1 -> normalisePixel $ template ! (Z :. 0 :. 0)
Z :. -1 :. 0 -> normalisePixel $ template ! (Z :. 0 :. 1)
Z :. -1 :. 1 -> normalisePixel $ template ! (Z :. 0 :. 2)
Z :. 0 :. -1 -> normalisePixel $ template ! (Z :. 1 :. 0)
Z :. 0 :. 0 -> normalisePixel $ template ! (Z :. 1 :. 1)
Z :. 0 :. 1 -> normalisePixel $ template ! (Z :. 1 :. 2)
Z :. 1 :. -1 -> normalisePixel $ template ! (Z :. 2 :. 0)
Z :. 1 :. 0 -> normalisePixel $ template ! (Z :. 2 :. 1)
Z :. 1 :. 1 -> normalisePixel $ template ! (Z :. 2 :. 2)
_ -> Nothing
--8<---------------cut here---------------end--------------->8---
Thanks,
--
Rob