1.2 <GdkPixbufLoader>

Class: <GdkPixbufLoader>

It derives from <GObject>.

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 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 pixbuf-loader:write? to send the data to it. When done, pixbuf-loader:close? should be called to end the stream and finalize everything.

The loader will emit three important signals throughout the process:

  • pixbuf-loader:size-prepared 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 pixbuf-loader:set-size in response to this signal.
  • pixbuf-loader:area-prepared will be emitted as soon as the pixbuf of the desired has been allocated. You can obtain the <GdkPixbuf> instance by calling pixbuf-loader:get-pixbuf. If you want to use it, simply acquire a reference to it. You can also call pixbuf-loader:get-pixbuf later to get the same pixbuf.
  • pixbuf-loader:area-updated 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 pixbuf-loader:area-prepared signal has been emitted, you can call pixbuf-loader:get-animation to get the <GdkPixbufAnimation> instance, and then call and GdkPixbuf.PixbufAnimation.get_iter to get a <GdkPixbufAnimationIter> to retrieve the pixbuf for the desired time stamp.

Procedures

Method: pixbuf-loader:close? self ⇒ %return
Method: close? self ⇒ %return

Informs a pixbuf loader that no further writes with pixbuf-loader:write? 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.

self

Passed: a <GdkPixbufLoader>.

A pixbuf loader.

%return

Returned: a boolean.

TRUE if all image data written so far was successfully passed out via the update_area signal

Method: pixbuf-loader:get-animation self ⇒ %return
Method: get-animation self ⇒ %return

Queries the GdkPixbufAnimation that a pixbuf loader is currently creating.

In general it only makes sense to call this function after the pixbuf-loader:area-prepared 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.

self

Passed: a <GdkPixbufLoader>.

A pixbuf loader

%return

Returned: a <GdkPixbufAnimation>, or #f.

The animation that the loader is currently loading

Method: pixbuf-loader:get-format self ⇒ %return
Method: get-format self ⇒ %return

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

self

Passed: a <GdkPixbufLoader>.

A pixbuf loader.

%return

Returned: a <GdkPixbufFormat>, or #f.

A <GdkPixbufFormat>

Method: pixbuf-loader:get-pixbuf self ⇒ %return
Method: get-pixbuf self ⇒ %return

Queries the <GdkPixbuf> that a pixbuf loader is currently creating.

In general it only makes sense to call this function after the pixbuf-loader:area-prepared 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 pixbuf-loader:write?, 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 gdk_pixbuf_animation_get_static_image()).

self

Passed: a <GdkPixbufLoader>.

A pixbuf loader.

%return

Returned: a <GdkPixbuf>, or #f.

The pixbuf that the loader is creating

Procedure: pixbuf-loader:new ⇒ %return

Creates a new pixbuf loader object.

%return

Returned: a <GdkPixbufLoader>.

A newly-created pixbuf loader.

Procedure: pixbuf-loader:new-with-mime-type mime-type ⇒ %return

Creates a new pixbuf loader object that always attempts to parse image data as if it were an image of MIME type mime-type, 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 pixbuf-format:get-mime-types on each of the <GdkPixbufFormat> structs returned by pixbuf:get-formats.

mime-type

Passed: a string.

the mime type to be loaded

%return

Returned: a <GdkPixbufLoader>.

A newly-created pixbuf loader.

Procedure: pixbuf-loader:new-with-type image-type ⇒ %return

Creates a new pixbuf loader object that always attempts to parse image data as if it were an image of type image-type, 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 pixbuf-format:get-name on each of the <GdkPixbufFormat> structs returned by pixbuf:get-formats.

image-type

Passed: a string.

name of the image format to be loaded with the image

%return

Returned: a <GdkPixbufLoader>.

A newly-created pixbuf loader.

Method: pixbuf-loader:set-size self width height
Method: set-size self width height

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 pixbuf-loader:set-size from a signal handler for the ::size-prepared signal.

Attempts to set the desired image size are ignored after the emission of the ::size-prepared signal.

self

Passed: a <GdkPixbufLoader>.

A pixbuf loader.

width

Passed: a 32-bit integer.

The desired width of the image being loaded.

height

Passed: a 32-bit integer.

The desired height of the image being loaded.

Method: pixbuf-loader:write-bytes? self buffer ⇒ %return
Method: write-bytes? self buffer ⇒ %return

Parses the next contents of the given image buffer.

self

Passed: a <GdkPixbufLoader>.

A pixbuf loader.

buffer

Passed: a <GBytes>.

The image data as a <GBytes> buffer.

%return

Returned: a boolean.

TRUE if the write was successful, or FALSE if the loader cannot parse the buffer

Method: pixbuf-loader:write? self buf ⇒ %return
Method: write? self buf ⇒ %return

Parses the next count bytes in the given image buffer.

self

Passed: a <GdkPixbufLoader>.

A pixbuf loader.

buf

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

Pointer to image data.

%return

Returned: a boolean.

TRUE if the write was successful, or FALSE if the loader cannot parse the buffer

count

Not passed: guile-gi gives the length of buf.

Length of the buf buffer in bytes.

Signals

Signal: pixbuf-loader:area-prepared

Connect a handler with (connect object pixbuf-loader:area-prepared handler). It is called as (handler self).

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

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

self

Passed: a <GdkPixbufLoader>.

Signal: pixbuf-loader:area-updated

Connect a handler with (connect object pixbuf-loader:area-updated handler). It is called as (handler self x y width height).

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.

self

Passed: a <GdkPixbufLoader>.

x

Passed: a 32-bit integer.

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

y

Passed: a 32-bit integer.

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

width

Passed: a 32-bit integer.

Width of updated area.

height

Passed: a 32-bit integer.

Height of updated area.

Signal: pixbuf-loader:closed

Connect a handler with (connect object pixbuf-loader:closed handler). It is called as (handler self).

This signal is emitted when pixbuf-loader:close? 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.

self

Passed: a <GdkPixbufLoader>.

Signal: pixbuf-loader:size-prepared

Connect a handler with (connect object pixbuf-loader:size-prepared handler). It is called as (handler self width height).

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 pixbuf-loader:set-size in response to this signal to set the desired size to which the image should be scaled.

self

Passed: a <GdkPixbufLoader>.

width

Passed: a 32-bit integer.

the original width of the image

height

Passed: a 32-bit integer.

the original height of the image

Virtual methods

Virtual method: pixbuf-loader:do-area-prepared implementor self

To override it in a new class, give register-type #:vfuncs `((area-prepared . ,procedure)). The procedure is called as (procedure self).

implementor

Passed: the class whose implementation to call: <GdkPixbufLoader>, or a class that derives from it, or its GType number.

self

Passed: a <GdkPixbufLoader>.

Virtual method: pixbuf-loader:do-area-updated implementor self x y width height

To override it in a new class, give register-type #:vfuncs `((area-updated . ,procedure)). The procedure is called as (procedure self x y width height).

implementor

Passed: the class whose implementation to call: <GdkPixbufLoader>, or a class that derives from it, or its GType number.

self

Passed: a <GdkPixbufLoader>.

x

Passed: a 32-bit integer.

y

Passed: a 32-bit integer.

width

Passed: a 32-bit integer.

height

Passed: a 32-bit integer.

Virtual method: pixbuf-loader:do-closed implementor self

To override it in a new class, give register-type #:vfuncs `((closed . ,procedure)). The procedure is called as (procedure self).

implementor

Passed: the class whose implementation to call: <GdkPixbufLoader>, or a class that derives from it, or its GType number.

self

Passed: a <GdkPixbufLoader>.

Virtual method: pixbuf-loader:do-size-prepared implementor self width height

To override it in a new class, give register-type #:vfuncs `((size-prepared . ,procedure)). The procedure is called as (procedure self width height).

implementor

Passed: the class whose implementation to call: <GdkPixbufLoader>, or a class that derives from it, or its GType number.

self

Passed: a <GdkPixbufLoader>.

width

Passed: a 32-bit integer.

height

Passed: a 32-bit integer.