gi-gdkpixbuf-2.0.31: GdkPixbuf bindings
CopyrightWill Thompson and Iñaki García Etxebarria
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellSafe-Inferred
LanguageHaskell2010

GI.GdkPixbuf.Objects.PixbufLoader

Description

Incremental image loader.

GdkPixbufLoader provides a way for applications to drive the process of loading an image, by letting them send the image data directly to the loader instead of having the loader read the data from a file. Applications can use this functionality instead of gdk_pixbuf_new_from_file() or gdk_pixbuf_animation_new_from_file() when they need to parse image data in small chunks. For example, it should be used when reading an image from a (potentially) slow network connection, or when loading an extremely large file.

To use GdkPixbufLoader to load an image, create a new instance, and call pixbufLoaderWrite to send the data to it. When done, pixbufLoaderClose should be called to end the stream and finalize everything.

The loader will emit three important signals throughout the process:

  • PixbufLoader::sizePrepared will be emitted as soon as the image has enough information to determine the size of the image to be used. If you want to scale the image while loading it, you can call pixbufLoaderSetSize in response to this signal.
  • PixbufLoader::areaPrepared will be emitted as soon as the pixbuf of the desired has been allocated. You can obtain the GdkPixbuf instance by calling pixbufLoaderGetPixbuf. If you want to use it, simply acquire a reference to it. You can also call gdk_pixbuf_loader_get_pixbuf() later to get the same pixbuf.
  • PixbufLoader::areaUpdated will be emitted every time a region is updated. This way you can update a partially completed image. Note that you do not know anything about the completeness of an image from the updated area. For example, in an interlaced image you will need to make several passes before the image is done loading.

Loading an animation

Loading an animation is almost as easy as loading an image. Once the first PixbufLoader::areaPrepared signal has been emitted, you can call pixbufLoaderGetAnimation to get the PixbufAnimation instance, and then call and pixbufAnimationGetIter to get a PixbufAnimationIter to retrieve the pixbuf for the desired time stamp.

Synopsis

Exported types

newtype PixbufLoader Source #

Memory-managed wrapper type.

Constructors

PixbufLoader (ManagedPtr PixbufLoader) 

Instances

Instances details
Eq PixbufLoader Source # 
Instance details

Defined in GI.GdkPixbuf.Objects.PixbufLoader

GObject PixbufLoader Source # 
Instance details

Defined in GI.GdkPixbuf.Objects.PixbufLoader

ManagedPtrNewtype PixbufLoader Source # 
Instance details

Defined in GI.GdkPixbuf.Objects.PixbufLoader

Methods

toManagedPtr :: PixbufLoader -> ManagedPtr PixbufLoader

TypedObject PixbufLoader Source # 
Instance details

Defined in GI.GdkPixbuf.Objects.PixbufLoader

Methods

glibType :: IO GType

HasParentTypes PixbufLoader Source # 
Instance details

Defined in GI.GdkPixbuf.Objects.PixbufLoader

IsGValue (Maybe PixbufLoader) Source #

Convert PixbufLoader to and from GValue. See toGValue and fromGValue.

Instance details

Defined in GI.GdkPixbuf.Objects.PixbufLoader

Methods

gvalueGType_ :: IO GType

gvalueSet_ :: Ptr GValue -> Maybe PixbufLoader -> IO ()

gvalueGet_ :: Ptr GValue -> IO (Maybe PixbufLoader)

type ParentTypes PixbufLoader Source # 
Instance details

Defined in GI.GdkPixbuf.Objects.PixbufLoader

type ParentTypes PixbufLoader = '[Object]

class (GObject o, IsDescendantOf PixbufLoader o) => IsPixbufLoader o Source #

Type class for types which can be safely cast to PixbufLoader, for instance with toPixbufLoader.

Instances

Instances details
(GObject o, IsDescendantOf PixbufLoader o) => IsPixbufLoader o Source # 
Instance details

Defined in GI.GdkPixbuf.Objects.PixbufLoader

toPixbufLoader :: (MonadIO m, IsPixbufLoader o) => o -> m PixbufLoader Source #

Cast to PixbufLoader, for types for which this is known to be safe. For general casts, use castTo.

Methods

close

pixbufLoaderClose Source #

Arguments

:: (HasCallStack, MonadIO m, IsPixbufLoader a) 
=> a

loader: A pixbuf loader.

-> m ()

(Can throw GError)

Informs a pixbuf loader that no further writes with pixbufLoaderWrite will occur, so that it can free its internal loading structures.

This function also tries to parse any data that hasn't yet been parsed; if the remaining data is partial or corrupt, an error will be returned.

If FALSE is returned, error will be set to an error from the GDK_PIXBUF_ERROR or G_FILE_ERROR domains.

If you're just cancelling a load rather than expecting it to be finished, passing NULL for error to ignore it is reasonable.

Remember that this function does not release a reference on the loader, so you will need to explicitly release any reference you hold.

getAnimation

pixbufLoaderGetAnimation Source #

Arguments

:: (HasCallStack, MonadIO m, IsPixbufLoader a) 
=> a

loader: A pixbuf loader

-> m (Maybe PixbufAnimation)

Returns: The animation that the loader is currently loading

Queries the PixbufAnimation that a pixbuf loader is currently creating.

In general it only makes sense to call this function after the PixbufLoader::areaPrepared signal has been emitted by the loader.

If the loader doesn't have enough bytes yet, and hasn't emitted the area-prepared signal, this function will return NULL.

getFormat

pixbufLoaderGetFormat Source #

Arguments

:: (HasCallStack, MonadIO m, IsPixbufLoader a) 
=> a

loader: A pixbuf loader.

-> m (Maybe PixbufFormat)

Returns: A PixbufFormat

Obtains the available information about the format of the currently loading image file.

Since: 2.2

getPixbuf

pixbufLoaderGetPixbuf Source #

Arguments

:: (HasCallStack, MonadIO m, IsPixbufLoader a) 
=> a

loader: A pixbuf loader.

-> m (Maybe Pixbuf)

Returns: The pixbuf that the loader is creating

Queries the Pixbuf that a pixbuf loader is currently creating.

In general it only makes sense to call this function after the PixbufLoader::areaPrepared signal has been emitted by the loader; this means that enough data has been read to know the size of the image that will be allocated.

If the loader has not received enough data via pixbufLoaderWrite, then this function returns NULL.

The returned pixbuf will be the same in all future calls to the loader, so if you want to keep using it, you should acquire a reference to it.

Additionally, if the loader is an animation, it will return the "static image" of the animation (see pixbufAnimationGetStaticImage).

new

pixbufLoaderNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> m PixbufLoader

Returns: A newly-created pixbuf loader.

Creates a new pixbuf loader object.

newWithMimeType

pixbufLoaderNewWithMimeType Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Text

mimeType: the mime type to be loaded

-> m PixbufLoader

Returns: A newly-created pixbuf loader. (Can throw GError)

Creates a new pixbuf loader object that always attempts to parse image data as if it were an image of MIME type mimeType, instead of identifying the type automatically.

This function is useful if you want an error if the image isn't the expected MIME type; for loading image formats that can't be reliably identified by looking at the data; or if the user manually forces a specific MIME type.

The list of supported mime types depends on what image loaders are installed, but typically "image/png", "image/jpeg", "image/gif", "image/tiff" and "image/x-xpixmap" are among the supported mime types. To obtain the full list of supported mime types, call pixbufFormatGetMimeTypes on each of the PixbufFormat structs returned by pixbufGetFormats.

Since: 2.4

newWithType

pixbufLoaderNewWithType Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Text

imageType: name of the image format to be loaded with the image

-> m PixbufLoader

Returns: A newly-created pixbuf loader. (Can throw GError)

Creates a new pixbuf loader object that always attempts to parse image data as if it were an image of type imageType, instead of identifying the type automatically.

This function is useful if you want an error if the image isn't the expected type; for loading image formats that can't be reliably identified by looking at the data; or if the user manually forces a specific type.

The list of supported image formats depends on what image loaders are installed, but typically "png", "jpeg", "gif", "tiff" and "xpm" are among the supported formats. To obtain the full list of supported image formats, call pixbufFormatGetName on each of the PixbufFormat structs returned by pixbufGetFormats.

setSize

pixbufLoaderSetSize Source #

Arguments

:: (HasCallStack, MonadIO m, IsPixbufLoader a) 
=> a

loader: A pixbuf loader.

-> Int32

width: The desired width of the image being loaded.

-> Int32

height: The desired height of the image being loaded.

-> m () 

Causes the image to be scaled while it is loaded.

The desired image size can be determined relative to the original size of the image by calling pixbufLoaderSetSize from a signal handler for the sizePrepared signal.

Attempts to set the desired image size are ignored after the emission of the sizePrepared signal.

Since: 2.2

write

pixbufLoaderWrite Source #

Arguments

:: (HasCallStack, MonadIO m, IsPixbufLoader a) 
=> a

loader: A pixbuf loader.

-> ByteString

buf: Pointer to image data.

-> m ()

(Can throw GError)

Parses the next count bytes in the given image buffer.

writeBytes

pixbufLoaderWriteBytes Source #

Arguments

:: (HasCallStack, MonadIO m, IsPixbufLoader a) 
=> a

loader: A pixbuf loader.

-> Bytes

buffer: The image data as a GBytes buffer.

-> m ()

(Can throw GError)

Parses the next contents of the given image buffer.

Since: 2.30

Signals

areaPrepared

type PixbufLoaderAreaPreparedCallback = IO () Source #

This signal is emitted when the pixbuf loader has allocated the pixbuf in the desired size.

After this signal is emitted, applications can call pixbufLoaderGetPixbuf to fetch the partially-loaded pixbuf.

afterPixbufLoaderAreaPrepared :: (IsPixbufLoader a, MonadIO m) => a -> ((?self :: a) => PixbufLoaderAreaPreparedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the areaPrepared signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after pixbufLoader #areaPrepared callback

By default the object invoking the signal is not passed to the callback. If you need to access it, you can use the implit ?self parameter. Note that this requires activating the ImplicitParams GHC extension.

onPixbufLoaderAreaPrepared :: (IsPixbufLoader a, MonadIO m) => a -> ((?self :: a) => PixbufLoaderAreaPreparedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the areaPrepared signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on pixbufLoader #areaPrepared callback

areaUpdated

type PixbufLoaderAreaUpdatedCallback Source #

Arguments

 = Int32

x: X offset of upper-left corner of the updated area.

-> Int32

y: Y offset of upper-left corner of the updated area.

-> Int32

width: Width of updated area.

-> Int32

height: Height of updated area.

-> IO () 

This signal is emitted when a significant area of the image being loaded has been updated.

Normally it means that a complete scanline has been read in, but it could be a different area as well.

Applications can use this signal to know when to repaint areas of an image that is being loaded.

afterPixbufLoaderAreaUpdated :: (IsPixbufLoader a, MonadIO m) => a -> ((?self :: a) => PixbufLoaderAreaUpdatedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the areaUpdated signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after pixbufLoader #areaUpdated callback

By default the object invoking the signal is not passed to the callback. If you need to access it, you can use the implit ?self parameter. Note that this requires activating the ImplicitParams GHC extension.

onPixbufLoaderAreaUpdated :: (IsPixbufLoader a, MonadIO m) => a -> ((?self :: a) => PixbufLoaderAreaUpdatedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the areaUpdated signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on pixbufLoader #areaUpdated callback

closed

type PixbufLoaderClosedCallback = IO () Source #

This signal is emitted when pixbufLoaderClose is called.

It can be used by different parts of an application to receive notification when an image loader is closed by the code that drives it.

afterPixbufLoaderClosed :: (IsPixbufLoader a, MonadIO m) => a -> ((?self :: a) => PixbufLoaderClosedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the closed signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after pixbufLoader #closed callback

By default the object invoking the signal is not passed to the callback. If you need to access it, you can use the implit ?self parameter. Note that this requires activating the ImplicitParams GHC extension.

onPixbufLoaderClosed :: (IsPixbufLoader a, MonadIO m) => a -> ((?self :: a) => PixbufLoaderClosedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the closed signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on pixbufLoader #closed callback

sizePrepared

type PixbufLoaderSizePreparedCallback Source #

Arguments

 = Int32

width: the original width of the image

-> Int32

height: the original height of the image

-> IO () 

This signal is emitted when the pixbuf loader has been fed the initial amount of data that is required to figure out the size of the image that it will create.

Applications can call pixbufLoaderSetSize in response to this signal to set the desired size to which the image should be scaled.

afterPixbufLoaderSizePrepared :: (IsPixbufLoader a, MonadIO m) => a -> ((?self :: a) => PixbufLoaderSizePreparedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the sizePrepared signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after pixbufLoader #sizePrepared callback

By default the object invoking the signal is not passed to the callback. If you need to access it, you can use the implit ?self parameter. Note that this requires activating the ImplicitParams GHC extension.

onPixbufLoaderSizePrepared :: (IsPixbufLoader a, MonadIO m) => a -> ((?self :: a) => PixbufLoaderSizePreparedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the sizePrepared signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on pixbufLoader #sizePrepared callback