
Untitled
By: a guest on
Mar 27th, 2012 | syntax:
Haskell | size: 1.41 KB | hits: 37 | expires: Never
-----
convertImage
(?transColor :: (Word8, Word8, Word8) -- ^ Transparency color.
,?ptrDest :: Ptr Word8 -- ^ Pointer to destination image.
,?ptrSrc :: Ptr Word8 -- ^ Pointer to source image.
,?width :: Int -- ^ Width of image in pixels.
,?height :: Int -- ^ Height of image in pixels.
,?slackPerLine :: Int -- ^ Number of bytes of slack space per line.
)
=>
-> Int -- ^ X position in the image.
-> Int -- ^ Y position in the image.
-> Int -- ^ Offset into source image, in bytes.
-> Int -- ^ Offset into destination image, in bytes.
-> IO ()
-- ^ Performs conversion between 24bit RGB and 32bit RGBA.
convertImage
posX posY
oSrc oDest
| posX == ?width
= convertImage 0 (posY + 1) (oSrc + ?slackPerLine) oDest
| posY == ?height
= return ()
| otherwise
= do
red <- peekByteOff ?ptrSrc (oSrc + 2)
green <- peekByteOff ?ptrSrc (oSrc + 1)
blue <- peekByteOff ?ptrSrc (oSrc + 0)
pokeByteOff ?ptrDest (oDest + 3) red
pokeByteOff ?ptrDest (oDest + 2) green
pokeByteOff ?ptrDest (oDest + 1) blue
let (transRed, transGreen, transBlue)
= ?transColor
(if red == transRed
&& green == transGreen
&& blue == transBlue
then pokeByteOff ?ptrDest (oDest + 0) (0 :: Word8)
else pokeByteOff ?ptrDest (oDest + 0) (255 :: Word8))
convertImage
(posX + 1) posY
(oSrc + 3) (oDest + 4)