1
1
2
2
{-# LANGUAGE BangPatterns #-}
3
3
{-# LANGUAGE UnboxedTuples #-}
4
+ {-# LANGUAGE GeneralizedNewtypeDeriving #-}
4
5
5
6
module Graphics.Bling.Image (
6
7
@@ -15,6 +16,9 @@ module Graphics.Bling.Image (
15
16
imageWidth , imageHeight , sampleExtent ,
16
17
17
18
thaw , freeze ,
19
+
20
+ -- * The Image Transformer
21
+ ImageT , runImageT , evalImageT , execImageT
18
22
19
23
) where
20
24
@@ -299,3 +303,24 @@ rgbPixels img@(Img w h _ _ _) spw wnd = Prelude.zip xs clamped where
299
303
xs = filter (\ (x, y) -> x >= 0 && y >= 0 && x < w && y < h) $ coverWindow wnd
300
304
os = map (\ (x,y) -> (y * (imgW img)) + x) xs
301
305
306
+ newtype ImageT m a = ImageT { withImage :: MImage m -> m a }
307
+
308
+ {-
309
+ instance Monad m => Monad (ImageT m) where
310
+ return x = ImageT $ \_ -> return x
311
+ (>>=) (ImageT i1) k = ImageT (\i2 -> k i2)
312
+
313
+ -}
314
+
315
+ runImageT :: PrimMonad m => ImageT m a -> Image -> m (a , Image )
316
+ runImageT k img = do
317
+ mimg <- thaw img
318
+ result <- withImage k mimg
319
+ (img', _) <- freeze mimg
320
+ return (result, img')
321
+
322
+ execImageT :: PrimMonad m => ImageT m a -> Image -> m Image
323
+ execImageT k i = liftM snd $ runImageT k i
324
+
325
+ evalImageT :: PrimMonad m => ImageT m a -> Image -> m a
326
+ evalImageT k i = liftM fst $ runImageT k i
0 commit comments