1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
-----------------------------------------------------------------------------
-- |
-- Module : Graphics.UI.SDL.Color
-- Copyright : (c) David Himmelstrup 2005
-- License : BSD-like
--
-- Maintainer : lemmih@gmail.com
-- Stability : provisional
-- Portability : portable
--
-----------------------------------------------------------------------------
module Graphics.UI.SDL.Color
(Color (..)
,Pixel (..)
) where
import Foreign (castPtr,pokeArray)
import Data.Word (Word8,Word32)
import Foreign.Storable (Storable(..))
data Color
= Color
{ colorRed, colorGreen, colorBlue :: Word8 }
instance Storable Color where
sizeOf = const 4
alignment = const 1
peek ptr
= do r <- peekByteOff ptr 0
g <- peekByteOff ptr 1
b <- peekByteOff ptr 2
return (Color r g b)
poke ptr (Color r g b) = pokeArray (castPtr ptr) [r,g,b,0]
newtype Pixel = Pixel Word32 deriving (Show,Eq,Ord)
instance Storable Pixel where
sizeOf (Pixel v) = sizeOf v
alignment (Pixel v) = alignment v
peek p
= do v <- peek (castPtr p)
return $ Pixel v
poke p (Pixel v) = poke (castPtr p) v
|