Created
August 17, 2014 22:09
-
-
Save ssadler/316daa219ff412e1b5c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myReadPixels:: Int -> Int -> Int -> Int -> IO [Pixel] | |
myReadPixels x y w h = do | |
let arraySize = w * h * 4 | |
array <- mallocForeignPtrArray arraySize :: IO (ForeignPtr Word8) | |
let pos = Position (fromIntegral x) (fromIntegral y) | |
withForeignPtr array $ \ptr -> do | |
-- fromIntegral is needed because Position and Size store GLints not Ints | |
readPixels pos | |
(Size (fromIntegral w) (fromIntegral h)) | |
(PixelData RGBA UnsignedByte ptr) | |
peekArray arraySize ptr >>= return . pixelGroups | |
where | |
pixelGroups (a:b:c:d:xs) = (Pixel a b c d) : pixelGroups xs | |
pixelGroups [] = [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment