Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Mar 27th, 2012  |  syntax: Haskell  |  size: 1.41 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -----
  2. convertImage
  3.         (?transColor            :: (Word8, Word8, Word8)        -- ^ Transparency color.
  4.         ,?ptrDest               :: Ptr Word8                    -- ^ Pointer to destination image.
  5.         ,?ptrSrc                :: Ptr Word8                    -- ^ Pointer to source image.
  6.         ,?width         :: Int                          -- ^ Width of image in pixels.
  7.         ,?height                :: Int                          -- ^ Height of image in pixels.
  8.         ,?slackPerLine  :: Int                          -- ^ Number of bytes of slack space per line.
  9.         )
  10.     =>
  11.         -> Int                                                  -- ^ X position in the image.
  12.         -> Int                                                  -- ^ Y position in the image.
  13.  
  14.         -> Int                                                  -- ^ Offset into source image, in bytes.
  15.         -> Int                                                  -- ^ Offset into destination image, in bytes.
  16.         -> IO ()
  17.  
  18.  
  19. -- ^ Performs conversion between 24bit RGB and 32bit RGBA.
  20.  
  21. convertImage
  22.         posX  posY
  23.         oSrc  oDest            
  24.  
  25.  | posX == ?width
  26.  = convertImage 0 (posY + 1) (oSrc + ?slackPerLine) oDest
  27.  
  28.  | posY == ?height
  29.  = return ()
  30.  
  31.  | otherwise
  32.  = do
  33.         red     <- peekByteOff ?ptrSrc (oSrc + 2)
  34.         green   <- peekByteOff ?ptrSrc (oSrc + 1)
  35.         blue    <- peekByteOff ?ptrSrc (oSrc + 0)
  36.        
  37.         pokeByteOff ?ptrDest (oDest + 3) red
  38.         pokeByteOff ?ptrDest (oDest + 2) green
  39.         pokeByteOff ?ptrDest (oDest + 1) blue
  40.        
  41.         let (transRed, transGreen, transBlue)
  42.                 = ?transColor
  43.        
  44.         (if  red   == transRed
  45.           && green == transGreen
  46.           && blue  == transBlue
  47.                 then pokeByteOff ?ptrDest (oDest + 0) (0        :: Word8)
  48.                 else pokeByteOff ?ptrDest (oDest + 0) (255      :: Word8))
  49.                
  50.         convertImage
  51.                 (posX + 1) posY
  52.                 (oSrc + 3) (oDest + 4)