{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Graphics.Image.Interface.Vector (
VU(..), VS(..),
filter, ifilter,
toIx, fromIx
) where
import Prelude hiding (filter)
import qualified Data.Vector.Unboxed as U
import Graphics.Image.Interface as I
import Graphics.Image.Interface.Vector.Unboxed
import Graphics.Image.Interface.Vector.Storable
filter :: Array arr cs e =>
(Pixel cs e -> Bool)
-> Image arr cs e
-> U.Vector ((Int, Int), Pixel cs e)
filter f !img = U.filter (f . snd) $ U.imap addIx $ U.convert $ toVector img where
(_, n) = dims img
addIx !k !px = (toIx n k, px)
ifilter :: Array arr cs e =>
((Int, Int) -> Pixel cs e -> Bool)
-> Image arr cs e
-> U.Vector ((Int, Int), Pixel cs e)
ifilter f !img = U.filter (uncurry f) $ U.imap addIx $ U.convert $ toVector img where
(_, n) = dims img
addIx !k !px = (toIx n k, px)