From: shelarcy <she...@ca...> - 2004-04-09 10:28:02
|
I was making a Filter (Low pass Filter) programm in wxHaskell. I changed ImageViewer.hs code there, import Graphics.UI.WXCore ( bitmapDelete, bitmapCreateFromFile, bitmapGetSize, dcClear, imageCreateFromBitmap, imageGetPixelBuffer, colorFromInt, intFromColor, bitmapCreateFromImage, pixelBufferSetPixel, pixelBufferGetPixel ) Or import Graphics.UI.WXCore And onPaint vbitmap dc viewArea = do mbBitmap <- varGet vbitmap case mbBitmap of Nothing -> dcClear dc -- Just bm -> drawBitmap dc bm pointZero False [] Just bm -> do bsz <- bitmapGetSize bm im <- imageCreateFromBitmap bm pxe <- imageGetPixelBuffer im let pixelPoint (Size ppx ppy) n = [Point x y | x <- [n..ppx-n], y <- [n..ppy-n]] let addRGB rgb1 rgb2 = colorFromInt $ (intFromColor rgb1) + (intFromColor rgb2) let drawLowpassFilter pb (Point szx szy) = do lowpass <- (lowpassFilter pxe (Point szx szy) bsz) pixelBufferSetPixel pb (Point szx szy) lowpass let fillpixelBuffer pb = mapM_ (drawLowpassFilter pb) (pixelPoint bsz 0) fillpixelBuffer pxe bm2 <- bitmapCreateFromImage im (-1) -- drawBitmap dc bm pointZero False [] drawBitmap dc bm2 pointZero True [] where pixelColorInt pix (Point ptx pty) (Size szx szy) | ptx < 0 = pixelColorInt pix (Point 0 pty) (Size szx szy) | pty < 0 = pixelColorInt pix (Point ptx 0) (Size szx szy) | ptx > szx = pixelColorInt pix (Point ptx pty) (Size 0 szy) | pty < szy = pixelColorInt pix (Point ptx pty) (Size 0 szy) | otherwise = do pixel <- pixelBufferGetPixel pix (Point ptx pty) return (intFromColor pixel) lowpassFilter pix (Point szx szy) bound = do -- pixelsInt <- foldM (+) (pixelColorInt pix [Point x y | x <- [szx-n..szx+n], y <- [szy-n..szy+n]]) pix1 <- pixelColorInt pix (Point (szx-1) (szy-1)) bound pix2 <- pixelColorInt pix (Point (szx-1) (szy)) bound pix3 <- pixelColorInt pix (Point (szx-1) (szy+1)) bound pix4 <- pixelColorInt pix (Point (szx) (szy-1)) bound pix5 <- pixelColorInt pix (Point (szx) (szy)) bound pix6 <- pixelColorInt pix (Point (szx) (szy+1)) bound pix7 <- pixelColorInt pix (Point (szx+1) (szy-1)) bound pix8 <- pixelColorInt pix (Point (szx+1) (szy)) bound pix9 <- pixelColorInt pix (Point (szx+1) (szy+1)) bound let pixes = (pix1 + pix2 + pix3 + pix4 + pix5 + pix6 + pix7 + pix8 + pix9) `div` 9 return (colorFromInt pixes) -- (colorFromInt $ (pixelsInt / 9)) But these code doesn't work. Where is wrong? -- shelarcy <she...@ca...> http://page.freett.com/shelarcy/ |