{-# LANGUAGE ScopedTypeVariables, FlexibleInstances, MultiParamTypeClasses #-}
{-# OPTIONS_HADDOCK hide #-}
module Graphics.UI.Gtk.Gdk.PixbufData (
PixbufData,
mkPixbufData
) where
import System.Glib.FFI
import Graphics.UI.Gtk.Types
import Data.Array.Base ( MArray(..), newArray_, unsafeRead, unsafeWrite,
getBounds, getNumElements )
data PixbufData i e = PixbufData !Pixbuf
{-# UNPACK #-} !(Ptr e)
!(i,i)
{-# UNPACK #-} !Int
mkPixbufData :: Storable e => Pixbuf -> Ptr e -> Int -> PixbufData Int e
mkPixbufData pb (ptr :: Ptr e) size =
PixbufData pb ptr (0, count) count
where count = fromIntegral (size `div` sizeOf (undefined :: e))
instance Storable e => MArray PixbufData e IO where
newArray (l,u) e = error "Gtk.Gdk.Pixbuf.newArray: not implemented"
newArray_ (l,u) = error "Gtk.Gdk.Pixbuf.newArray_: not implemented"
{-# INLINE unsafeRead #-}
unsafeRead (PixbufData (Pixbuf pb) pixPtr _ _) idx = do
e <- peekElemOff pixPtr idx
touchForeignPtr pb
return e
{-# INLINE unsafeWrite #-}
unsafeWrite (PixbufData (Pixbuf pb) pixPtr _ _) idx elem = do
pokeElemOff pixPtr idx elem
touchForeignPtr pb
{-# INLINE getBounds #-}
getBounds (PixbufData _ _ bd _) = return bd
{-# INLINE getNumElements #-}
getNumElements (PixbufData _ _ _ count) = return count