PixbufLoaderProtocol

public protocol PixbufLoaderProtocol : ObjectProtocol

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 [methodGdkPixbuf.PixbufLoader.write] to send the data to it. When done, [methodGdkPixbuf.PixbufLoader.close] should be called to end the stream and finalize everything.

The loader will emit three important signals throughout the process:

  • [signalGdkPixbuf.PixbufLoader::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 [methodGdkPixbuf.PixbufLoader.set_size] in response to this signal.
  • [signalGdkPixbuf.PixbufLoader::area-prepared] will be emitted as soon as the pixbuf of the desired has been allocated. You can obtain the GdkPixbuf instance by calling [methodGdkPixbuf.PixbufLoader.get_pixbuf]. 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.
  • [signalGdkPixbuf.PixbufLoader::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 [signalGdkPixbuf.PixbufLoader::area-prepared] signal has been emitted, you can call [methodGdkPixbuf.PixbufLoader.get_animation] to get the [classGdkPixbuf.PixbufAnimation] instance, and then call and [methodGdkPixbuf.PixbufAnimation.get_iter] to get a [classGdkPixbuf.PixbufAnimationIter] to retrieve the pixbuf for the desired time stamp.

The PixbufLoaderProtocol protocol exposes the methods and properties of an underlying GdkPixbufLoader instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see PixbufLoader. Alternatively, use PixbufLoaderRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GdkPixbufLoader instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • pixbuf_loader_ptr Default implementation

    Typed pointer to the underlying GdkPixbufLoader instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GdkPixbufLoader instance.

    Declaration

    Swift

    var pixbuf_loader_ptr: UnsafeMutablePointer<GdkPixbufLoader>! { get }
  • Required Initialiser for types conforming to PixbufLoaderProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

PixbufLoader signals

  • Connect a Swift signal handler to the given, typed PixbufLoaderSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: PixbufLoaderSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    handler

    The Swift signal handler (function or callback) to invoke on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

  • Connect a C signal handler to the given, typed PixbufLoaderSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: PixbufLoaderSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    signalHandler

    The C function to be called on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

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

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

    Note

    This represents the underlying area-prepared signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onAreaPrepared(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PixbufLoaderRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    handler

    The signal handler to call Run the given callback whenever the areaPrepared signal is emitted

  • areaPreparedSignal Extension method

    Typed area-prepared signal for using the connect(signal:) methods

    Declaration

    Swift

    static var areaPreparedSignal: PixbufLoaderSignalName { get }
  • 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.

    Note

    This represents the underlying area-updated signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onAreaUpdated(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PixbufLoaderRef, _ x: Int, _ y: Int, _ width: Int, _ height: Int) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    x

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

    y

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

    width

    Width of updated area.

    height

    Height of updated area.

    handler

    The signal handler to call Run the given callback whenever the areaUpdated signal is emitted

  • areaUpdatedSignal Extension method

    Typed area-updated signal for using the connect(signal:) methods

    Declaration

    Swift

    static var areaUpdatedSignal: PixbufLoaderSignalName { get }
  • onClosed(flags:handler:) Extension method

    This signal is emitted when gdk_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.

    Note

    This represents the underlying closed signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onClosed(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PixbufLoaderRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    handler

    The signal handler to call Run the given callback whenever the closed signal is emitted

  • closedSignal Extension method

    Typed closed signal for using the connect(signal:) methods

    Declaration

    Swift

    static var closedSignal: PixbufLoaderSignalName { get }
  • 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 gdk_pixbuf_loader_set_size() in response to this signal to set the desired size to which the image should be scaled.

    Note

    This represents the underlying size-prepared signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onSizePrepared(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PixbufLoaderRef, _ width: Int, _ height: Int) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    width

    the original width of the image

    height

    the original height of the image

    handler

    The signal handler to call Run the given callback whenever the sizePrepared signal is emitted

  • sizePreparedSignal Extension method

    Typed size-prepared signal for using the connect(signal:) methods

    Declaration

    Swift

    static var sizePreparedSignal: PixbufLoaderSignalName { get }

PixbufLoader Class: PixbufLoaderProtocol extension (methods and fields)

  • close() Extension method

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

    Declaration

    Swift

    @inlinable
    func close() throws -> Bool
  • getAnimation() Extension method

    Queries the GdkPixbufAnimation that a pixbuf loader is currently creating.

    In general it only makes sense to call this function after the [signalGdkPixbuf.PixbufLoader::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.

    Declaration

    Swift

    @inlinable
    func getAnimation() -> GdkPixBuf.PixbufAnimationRef!
  • getFormat() Extension method

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

    Declaration

    Swift

    @inlinable
    func getFormat() -> GdkPixBuf.PixbufFormatRef!
  • getPixbuf() Extension method

    Queries the GdkPixbuf that a pixbuf loader is currently creating.

    In general it only makes sense to call this function after the [signalGdkPixbuf.PixbufLoader::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 gdk_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()).

    Declaration

    Swift

    @inlinable
    func getPixbuf() -> GdkPixBuf.PixbufRef!
  • setSize(width:height:) Extension method

    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 gdk_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.

    Declaration

    Swift

    @inlinable
    func setSize(width: Int, height: Int)
  • write(buf:count:) Extension method

    Parses the next count bytes in the given image buffer.

    Declaration

    Swift

    @inlinable
    func write(buf: UnsafePointer<guchar>!, count: Int) throws -> Bool
  • writeBytes(buffer:) Extension method

    Parses the next contents of the given image buffer.

    Declaration

    Swift

    @inlinable
    func writeBytes<GLibBytesT>(buffer: GLibBytesT) throws -> Bool where GLibBytesT : BytesProtocol
  • animation Extension method

    Queries the GdkPixbufAnimation that a pixbuf loader is currently creating.

    In general it only makes sense to call this function after the [signalGdkPixbuf.PixbufLoader::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.

    Declaration

    Swift

    @inlinable
    var animation: GdkPixBuf.PixbufAnimationRef! { get }
  • format Extension method

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

    Declaration

    Swift

    @inlinable
    var format: GdkPixBuf.PixbufFormatRef! { get }
  • pixbuf Extension method

    Queries the GdkPixbuf that a pixbuf loader is currently creating.

    In general it only makes sense to call this function after the [signalGdkPixbuf.PixbufLoader::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 gdk_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()).

    Declaration

    Swift

    @inlinable
    var pixbuf: GdkPixBuf.PixbufRef! { get }