Package ch.bailu.gtk.gdkpixbuf
Class PixbufLoader
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gdkpixbuf.PixbufLoader
- All Implemented Interfaces:
PointerInterface
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 [method@GdkPixbuf.PixbufLoader.write] to send the data
to it. When done, [method@GdkPixbuf.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 [method@GdkPixbuf.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
the `GdkPixbuf` instance by calling [method@GdkPixbuf.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.
- [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 [signal@GdkPixbuf.PixbufLoader::area-prepared] signal has been
emitted, you can call [method@GdkPixbuf.PixbufLoader.get_animation] to
get the [class@GdkPixbuf.PixbufAnimation] instance, and then call
and [method@GdkPixbuf.PixbufAnimation.get_iter] to get a
[class@GdkPixbuf.PixbufAnimationIter] to retrieve the pixbuf for the
desired time stamp.
`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 [method@GdkPixbuf.PixbufLoader.write] to send the data
to it. When done, [method@GdkPixbuf.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 [method@GdkPixbuf.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
the `GdkPixbuf` instance by calling [method@GdkPixbuf.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.
- [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 [signal@GdkPixbuf.PixbufLoader::area-prepared] signal has been
emitted, you can call [method@GdkPixbuf.PixbufLoader.get_animation] to
get the [class@GdkPixbuf.PixbufAnimation] instance, and then call
and [method@GdkPixbuf.PixbufAnimation.get_iter] to get a
[class@GdkPixbuf.PixbufAnimationIter] to retrieve the pixbuf for the
desired time stamp.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
close()
Informs a pixbuf loader that no further writes with
gdk_pixbuf_loader_write() will occur, so that it can free its
internal loading structures.Queries the #GdkPixbufAnimation that a pixbuf loader is currently creating.static ClassHandler
Obtains the available information about the format of the
currently loading image file.static int
static long
static TypeSystem.TypeSize
Queries the #GdkPixbuf that a pixbuf loader is currently creating.static long
static TypeSystem.TypeSize
static PixbufLoader
newWithMimeTypePixbufLoader
(Str mime_type) 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.static PixbufLoader
newWithMimeTypePixbufLoader
(String mime_type) 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.static PixbufLoader
newWithTypePixbufLoader
(Str image_type) 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.static PixbufLoader
newWithTypePixbufLoader
(String image_type) 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.Connect to signal "area-prepared".Connect to signal "area-updated".onClosed
(PixbufLoader.OnClosed signal) Connect to signal "closed".Connect to signal "size-prepared".void
setSize
(int width, int height) Causes the image to be scaled while it is loaded.boolean
writeBytes
(Bytes buffer) Parses the next contents of the given image buffer.Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_AREA_PREPARED
- See Also:
-
SIGNAL_ON_AREA_UPDATED
- See Also:
-
SIGNAL_ON_CLOSED
- See Also:
-
SIGNAL_ON_SIZE_PREPARED
- See Also:
-
-
Constructor Details
-
PixbufLoader
-
PixbufLoader
public PixbufLoader()Creates a new pixbuf loader object.
-
-
Method Details
-
getClassHandler
-
newWithMimeTypePixbufLoader
public static PixbufLoader newWithMimeTypePixbufLoader(@Nonnull Str mime_type) throws AllocationError 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
gdk_pixbuf_format_get_mime_types() on each of the #GdkPixbufFormat
structs returned by gdk_pixbuf_get_formats().- Parameters:
mime_type
- the mime type to be loaded- Returns:
- A newly-created pixbuf loader.
- Throws:
AllocationError
-
newWithMimeTypePixbufLoader
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
gdk_pixbuf_format_get_mime_types() on each of the #GdkPixbufFormat
structs returned by gdk_pixbuf_get_formats().- Parameters:
mime_type
- the mime type to be loaded- Returns:
- A newly-created pixbuf loader.
- Throws:
AllocationError
-
newWithTypePixbufLoader
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 gdk_pixbuf_format_get_name() on each
of the #GdkPixbufFormat structs returned by gdk_pixbuf_get_formats().- Parameters:
image_type
- name of the image format to be loaded with the image- Returns:
- A newly-created pixbuf loader.
- Throws:
AllocationError
-
newWithTypePixbufLoader
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 gdk_pixbuf_format_get_name() on each
of the #GdkPixbufFormat structs returned by gdk_pixbuf_get_formats().- Parameters:
image_type
- name of the image format to be loaded with the image- Returns:
- A newly-created pixbuf loader.
- Throws:
AllocationError
-
close
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.- Returns:
- `TRUE` if all image data written so far was successfully passed out via the update_area signal
- Throws:
AllocationError
-
getAnimation
Queries the #GdkPixbufAnimation that 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-prepared`
signal, this function will return `NULL`.- Returns:
- The animation that the loader is currently loading
-
getFormat
Obtains the available information about the format of the
currently loading image file.- Returns:
- A #GdkPixbufFormat
-
getPixbuf
Queries the #GdkPixbuf that 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 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()).- Returns:
- The pixbuf that the loader is creating
-
setSize
public void setSize(int width, int 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 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.- Parameters:
width
- The desired width of the image being loaded.height
- The desired height of the image being loaded.
-
writeBytes
Parses the next contents of the given image buffer.- Parameters:
buffer
- The image data as a `GBytes` buffer.- Returns:
- `TRUE` if the write was successful, or `FALSE` if the loader cannot parse the buffer
- Throws:
AllocationError
-
onAreaPrepared
Connect to signal "area-prepared".
SeePixbufLoader.OnAreaPrepared.onAreaPrepared()
for signal description.
FieldSIGNAL_ON_AREA_PREPARED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onAreaUpdated
Connect to signal "area-updated".
SeePixbufLoader.OnAreaUpdated.onAreaUpdated(int, int, int, int)
for signal description.
FieldSIGNAL_ON_AREA_UPDATED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onClosed
Connect to signal "closed".
SeePixbufLoader.OnClosed.onClosed()
for signal description.
FieldSIGNAL_ON_CLOSED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onSizePrepared
Connect to signal "size-prepared".
SeePixbufLoader.OnSizePrepared.onSizePrepared(int, int)
for signal description.
FieldSIGNAL_ON_SIZE_PREPARED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-