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:
- [signal
GdkPixbuf.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. - [signal
GdkPixbuf.PixbufLoader::area-prepared] will be emitted as soon as the pixbuf of the desired has been allocated. You can obtain theGdkPixbufinstance by calling [methodGdkPixbuf.PixbufLoader.get_pixbuf]. If you want to use it, simply acquire a reference to it. You can also callgdk_pixbuf_loader_get_pixbuf()later to get the same pixbuf. - [signal
GdkPixbuf.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.
-
Untyped pointer to the underlying
GdkPixbufLoaderinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
pixbuf_loader_ptrDefault implementationTyped pointer to the underlying
GdkPixbufLoaderinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GdkPixbufLoaderinstance.Declaration
Swift
var pixbuf_loader_ptr: UnsafeMutablePointer<GdkPixbufLoader>! { get } -
Required Initialiser for types conforming to
PixbufLoaderProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
connect(signal:Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
PixbufLoaderSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: PixbufLoaderSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatahandlerThe 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(signal:Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
PixbufLoaderSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: PixbufLoaderSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatasignalHandlerThe C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
onAreaPrepared(flags:Extension methodhandler: ) 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 underlyingarea-preparedsignalDeclaration
Swift
@discardableResult @inlinable func onAreaPrepared(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PixbufLoaderRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
areaPreparedsignal is emitted -
areaPreparedSignalExtension methodTyped
area-preparedsignal for using theconnect(signal:)methodsDeclaration
Swift
static var areaPreparedSignal: PixbufLoaderSignalName { get } -
onAreaUpdated(flags:Extension methodhandler: ) 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 underlyingarea-updatedsignalDeclaration
Swift
@discardableResult @inlinable func onAreaUpdated(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PixbufLoaderRef, _ x: Int, _ y: Int, _ width: Int, _ height: Int) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
xX offset of upper-left corner of the updated area.
yY offset of upper-left corner of the updated area.
widthWidth of updated area.
heightHeight of updated area.
handlerThe signal handler to call Run the given callback whenever the
areaUpdatedsignal is emitted -
areaUpdatedSignalExtension methodTyped
area-updatedsignal for using theconnect(signal:)methodsDeclaration
Swift
static var areaUpdatedSignal: PixbufLoaderSignalName { get } -
onClosed(flags:Extension methodhandler: ) 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 underlyingclosedsignalDeclaration
Swift
@discardableResult @inlinable func onClosed(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PixbufLoaderRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
closedsignal is emitted -
closedSignalExtension methodTyped
closedsignal for using theconnect(signal:)methodsDeclaration
Swift
static var closedSignal: PixbufLoaderSignalName { get } -
onSizePrepared(flags:Extension methodhandler: ) 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 underlyingsize-preparedsignalDeclaration
Swift
@discardableResult @inlinable func onSizePrepared(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PixbufLoaderRef, _ width: Int, _ height: Int) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
widththe original width of the image
heightthe original height of the image
handlerThe signal handler to call Run the given callback whenever the
sizePreparedsignal is emitted -
sizePreparedSignalExtension methodTyped
size-preparedsignal for using theconnect(signal:)methodsDeclaration
Swift
static var sizePreparedSignal: PixbufLoaderSignalName { get }
-
close()Extension methodInforms 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
FALSEis returned,errorwill be set to an error from theGDK_PIXBUF_ERRORorG_FILE_ERRORdomains.If you’re just cancelling a load rather than expecting it to be finished, passing
NULLforerrorto 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 methodQueries the
GdkPixbufAnimationthat a pixbuf loader is currently creating.In general it only makes sense to call this function after the [signal
GdkPixbuf.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-preparedsignal, this function will returnNULL.Declaration
Swift
@inlinable func getAnimation() -> GdkPixBuf.PixbufAnimationRef! -
getFormat()Extension methodObtains the available information about the format of the currently loading image file.
Declaration
Swift
@inlinable func getFormat() -> GdkPixBuf.PixbufFormatRef! -
getPixbuf()Extension methodQueries the
GdkPixbufthat a pixbuf loader is currently creating.In general it only makes sense to call this function after the [signal
GdkPixbuf.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 returnsNULL.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:Extension methodheight: ) 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 thesize-preparedsignal.Attempts to set the desired image size are ignored after the emission of the
size-preparedsignal.Declaration
Swift
@inlinable func setSize(width: Int, height: Int) -
write(buf:Extension methodcount: ) Parses the next
countbytes 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 -
animationExtension methodQueries the
GdkPixbufAnimationthat a pixbuf loader is currently creating.In general it only makes sense to call this function after the [signal
GdkPixbuf.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-preparedsignal, this function will returnNULL.Declaration
Swift
@inlinable var animation: GdkPixBuf.PixbufAnimationRef! { get } -
formatExtension methodObtains the available information about the format of the currently loading image file.
Declaration
Swift
@inlinable var format: GdkPixBuf.PixbufFormatRef! { get } -
pixbufExtension methodQueries the
GdkPixbufthat a pixbuf loader is currently creating.In general it only makes sense to call this function after the [signal
GdkPixbuf.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 returnsNULL.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 }
View on GitHub
Install in Dash
PixbufLoaderProtocol Protocol Reference