module Graphics.UI.Gtk.Gdk.PixbufData (
PixbufData,
mkPixbufData
) where
import System.Glib.FFI
import Graphics.UI.Gtk.Types
import Data.Ix
import Data.Array.Base ( MArray, newArray, newArray_, unsafeRead, unsafeWrite,
#if __GLASGOW_HASKELL__ < 605
HasBounds, bounds
#else
getBounds
#endif
#if __GLASGOW_HASKELL__ >= 608
,getNumElements
#endif
)
data Ix i => PixbufData i e = PixbufData !Pixbuf
!(Ptr e)
!(i,i)
!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))
#if __GLASGOW_HASKELL__ < 605
instance HasBounds PixbufData where
bounds (PixbufData pb ptr bd cnt) = bd
#endif
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"
unsafeRead (PixbufData (Pixbuf pb) pixPtr _ _) idx = do
e <- peekElemOff pixPtr idx
touchForeignPtr pb
return e
unsafeWrite (PixbufData (Pixbuf pb) pixPtr _ _) idx elem = do
pokeElemOff pixPtr idx elem
touchForeignPtr pb
#if __GLASGOW_HASKELL__ >= 605
getBounds (PixbufData _ _ bd _) = return bd
#endif
#if __GLASGOW_HASKELL__ >= 608
getNumElements (PixbufData _ _ _ count) = return count
#endif