1
<refentry id="GdkPixbufLoader">
3
<refentrytitle>GdkPixbufLoader</refentrytitle>
4
<manvolnum>3</manvolnum>
5
<refmiscinfo>GDK-PIXBUF Library</refmiscinfo>
9
<refname>GdkPixbufLoader</refname><refpurpose>Application-driven progressive image loading.</refpurpose>
12
<refsynopsisdiv><title>Synopsis</title>
15
#include <gdk-pixbuf/gdk-pixbuf.h>
18
#define <link linkend="GDK-PIXBUF-LOADER-CAPS">GDK_PIXBUF_LOADER</link> (obj)
19
<link linkend="GdkPixbufLoader">GdkPixbufLoader</link>* <link linkend="gdk-pixbuf-loader-new">gdk_pixbuf_loader_new</link> (void);
20
<link linkend="gboolean">gboolean</link> <link linkend="gdk-pixbuf-loader-write">gdk_pixbuf_loader_write</link> (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *loader,
21
const <link linkend="guchar">guchar</link> *buf,
22
<link linkend="size-t">size_t</link> count);
23
<link linkend="GdkPixbuf">GdkPixbuf</link>* <link linkend="gdk-pixbuf-loader-get-pixbuf">gdk_pixbuf_loader_get_pixbuf</link> (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *loader);
24
<link linkend="GdkPixbufAnimation">GdkPixbufAnimation</link>* <link linkend="gdk-pixbuf-loader-get-animation">gdk_pixbuf_loader_get_animation</link>
25
(<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *loader);
26
void <link linkend="gdk-pixbuf-loader-close">gdk_pixbuf_loader_close</link> (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *loader);
33
<title>Object Hierarchy</title>
36
<link linkend="GtkObject">GtkObject</link>
44
<title>Signal Prototypes</title>
47
"<link linkend="GdkPixbufLoader-area-updated">area-updated</link>"
48
void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
49
<link linkend="gint">gint</link> arg1,
50
<link linkend="gint">gint</link> arg2,
51
<link linkend="gint">gint</link> arg3,
52
<link linkend="gint">gint</link> arg4,
53
<link linkend="gpointer">gpointer</link> user_data);
54
"<link linkend="GdkPixbufLoader-area-prepared">area-prepared</link>"
55
void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
56
<link linkend="gpointer">gpointer</link> user_data);
57
"<link linkend="GdkPixbufLoader-frame-done">frame-done</link>"
58
void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
59
<link linkend="gpointer">gpointer</link> arg1,
60
<link linkend="gpointer">gpointer</link> user_data);
61
"<link linkend="GdkPixbufLoader-animation-done">animation-done</link>"
62
void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
63
<link linkend="gpointer">gpointer</link> user_data);
64
"<link linkend="GdkPixbufLoader-closed">closed</link>" void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
65
<link linkend="gpointer">gpointer</link> user_data);
71
<title>Description</title>
73
<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> provides a way for applications to drive the
74
process of loading an image, by letting them send the image data
75
directly to the loader instead of having the loader read the data
76
from a file. Applications can use this functionality instead of
77
<link linkend="gdk-pixbuf-new-from-file">gdk_pixbuf_new_from_file</link>() when they need to parse image data in
78
small chunks. For example, it should be used when reading an
79
image from a (potentially) slow network connection, or when
80
loading an extremely large file.
84
To use <link linkend="GdkPixbufLoader">GdkPixbufLoader</link> to load an image, just create a new one,
85
and call <link linkend="gdk-pixbuf-loader-write">gdk_pixbuf_loader_write</link>() to send the data to it. When
86
done, <link linkend="gdk-pixbuf-loader-close">gdk_pixbuf_loader_close</link>() should be called to end the stream
87
and finalize everything. The loader will emit two important
88
signals throughout the process. The first, "<link
89
linkend="GdkPixbufLoader-area-prepared">area_prepared</link>",
90
will be called as soon as the image has enough information to
91
determine the size of the image to be used. It will pass a
92
<parameter>GdkPixbuf</parameter> in. If you want to use it, you can simply ref it. In
93
addition, no actual information will be passed in yet, so the
94
pixbuf can be safely filled with any temporary graphics (or an
95
initial color) as needed. You can also call the
96
<link linkend="gdk-pixbuf-loader-get-pixbuf">gdk_pixbuf_loader_get_pixbuf</link>() once this signal has been emitted
97
and get the same pixbuf.
101
The other signal, "<link
102
linkend="GdkPixbufLoader-area-updated">area_updated</link>" gets
103
called every time a region is updated. This way you can update a
104
partially completed image. Note that you do not know anything
105
about the completeness of an image from the area updated. For
106
example, in an interlaced image, you need to make several passes
107
before the image is done loading.
111
<title>Loading an animation</title>
114
Loading an animation is a little more complex then loading an
115
image. In addition to the above signals, there is also a "<link
116
linkend="GdkPixbufLoader-frame-done">frame_done</link>" signal,
118
linkend="GdkPixbufLoader-animation-done">animation_done</link>"
119
signal. The first lets the application know that it is dealing
120
with an animation, instead of a static image. It also passes a
121
<link linkend="GdkPixbufFrame">GdkPixbufFrame</link> in the signal. As before, if you want to keep
122
the frame, you need to ref it. Once the first "<link
123
linkend="GdkPixbufLoader-frame-done">frame_done</link>" signal
124
has been emitted, you can call <link linkend="gdk-pixbuf-loader-get-animation">gdk_pixbuf_loader_get_animation</link>()
125
to get the <link linkend="GdkPixbufAnimation">GdkPixbufAnimation</link> struct. Each subsequent frame
126
goes through a similar lifecycle. For example "<link
127
linkend="GdkPixbufLoader-area-prepared">area_prepared</link>" is
128
re-emitted. Then "<link
129
linkend="GdkPixbufLoader-area-updated">area_updated</link>" is
130
emitted as many times as necessary. Finally, "<link
131
linkend="GdkPixbufLoader-animation-done">animation_done</link>"
132
is emitted as soon as all frames are done.
138
<title>Details</title>
140
<title><anchor id="GDK-PIXBUF-LOADER-CAPS">GDK_PIXBUF_LOADER()</title>
141
<programlisting>#define GDK_PIXBUF_LOADER(obj) (GTK_CHECK_CAST ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader))
144
Casts a <link linkend="GtkObject">GtkObject</link> to a <link linkend="GdkPixbufLoader">GdkPixbufLoader</link>.
145
</para><informaltable pgwide=1 frame="none" role="params">
147
<colspec colwidth="2*">
148
<colspec colwidth="8*">
150
<row><entry align="right"><parameter>obj</parameter> :</entry>
151
<entry>A GTK+ object.
155
</tbody></tgroup></informaltable></refsect2>
157
<title><anchor id="gdk-pixbuf-loader-new">gdk_pixbuf_loader_new ()</title>
158
<programlisting><link linkend="GdkPixbufLoader">GdkPixbufLoader</link>* gdk_pixbuf_loader_new (void);</programlisting>
160
Creates a new pixbuf loader object.</para>
163
</para><informaltable pgwide=1 frame="none" role="params">
165
<colspec colwidth="2*">
166
<colspec colwidth="8*">
168
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> A newly-created pixbuf loader.
170
</tbody></tgroup></informaltable></refsect2>
172
<title><anchor id="gdk-pixbuf-loader-write">gdk_pixbuf_loader_write ()</title>
173
<programlisting><link linkend="gboolean">gboolean</link> gdk_pixbuf_loader_write (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *loader,
174
const <link linkend="guchar">guchar</link> *buf,
175
<link linkend="size-t">size_t</link> count);</programlisting>
177
This will cause a pixbuf loader to parse the next <parameter>count</parameter> bytes of an image.
178
It will return TRUE if the data was loaded successfully, and FALSE if an
179
error occurred. In the latter case, the loader will be closed, and will not
180
accept further writes.</para>
183
</para><informaltable pgwide=1 frame="none" role="params">
185
<colspec colwidth="2*">
186
<colspec colwidth="8*">
188
<row><entry align="right"><parameter>loader</parameter> :</entry>
189
<entry> A pixbuf loader.
191
<row><entry align="right"><parameter>buf</parameter> :</entry>
192
<entry> Pointer to image data.
194
<row><entry align="right"><parameter>count</parameter> :</entry>
195
<entry> Length of the <parameter>buf</parameter> buffer in bytes.
197
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> <link linkend="TRUE-CAPS">TRUE</link> if the write was successful, or <link linkend="FALSE-CAPS">FALSE</link> if the loader
198
cannot parse the buffer.
200
</tbody></tgroup></informaltable></refsect2>
202
<title><anchor id="gdk-pixbuf-loader-get-pixbuf">gdk_pixbuf_loader_get_pixbuf ()</title>
203
<programlisting><link linkend="GdkPixbuf">GdkPixbuf</link>* gdk_pixbuf_loader_get_pixbuf (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *loader);</programlisting>
205
Queries the GdkPixbuf that a pixbuf loader is currently creating. In general
206
it only makes sense to call this function afer the "area_prepared" signal has
207
been emitted by the loader; this means that enough data has been read to know
208
the size of the image that will be allocated. If the loader has not received
209
enough data via <link linkend="gdk-pixbuf-loader-write">gdk_pixbuf_loader_write</link>(), then this function returns <literal>NULL</literal>.
210
The returned pixbuf will be the same in all future calls to the loader, so
211
simply calling <link linkend="gdk-pixbuf-ref">gdk_pixbuf_ref</link>() should be sufficient to continue using it. Additionally,
212
if the loader is an animation, it will return the first frame of the animation.</para>
215
</para><informaltable pgwide=1 frame="none" role="params">
217
<colspec colwidth="2*">
218
<colspec colwidth="8*">
220
<row><entry align="right"><parameter>loader</parameter> :</entry>
221
<entry> A pixbuf loader.
223
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> The GdkPixbuf that the loader is creating, or <literal>NULL</literal> if not
224
enough data has been read to determine how to create the image buffer.
226
</tbody></tgroup></informaltable></refsect2>
228
<title><anchor id="gdk-pixbuf-loader-get-animation">gdk_pixbuf_loader_get_animation ()</title>
229
<programlisting><link linkend="GdkPixbufAnimation">GdkPixbufAnimation</link>* gdk_pixbuf_loader_get_animation
230
(<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *loader);</programlisting>
232
Queries the GdkPixbufAnimation that a pixbuf loader is currently creating.
233
In general it only makes sense to call this function afer the "area_prepared"
234
signal has been emitted by the loader. If the image is not an animation,
235
then it will return <literal>NULL</literal>.</para>
238
</para><informaltable pgwide=1 frame="none" role="params">
240
<colspec colwidth="2*">
241
<colspec colwidth="8*">
243
<row><entry align="right"><parameter>loader</parameter> :</entry>
244
<entry> A pixbuf loader
246
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> The GdkPixbufAnimation that the loader is loading, or <literal>NULL</literal> if
247
not enough data has been read to determine the information.
249
</tbody></tgroup></informaltable></refsect2>
251
<title><anchor id="gdk-pixbuf-loader-close">gdk_pixbuf_loader_close ()</title>
252
<programlisting>void gdk_pixbuf_loader_close (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *loader);</programlisting>
254
Informs a pixbuf loader that no further writes with <link linkend="gdk-pixbuf-load-write">gdk_pixbuf_load_write</link>()
255
will occur, so that it can free its internal loading structures.</para>
258
</para><informaltable pgwide=1 frame="none" role="params">
260
<colspec colwidth="2*">
261
<colspec colwidth="8*">
263
<row><entry align="right"><parameter>loader</parameter> :</entry>
264
<entry> A pixbuf loader.
266
</tbody></tgroup></informaltable></refsect2>
271
<title>Signals</title>
272
<refsect2><title><anchor id="GdkPixbufLoader-area-updated">The "area-updated" signal</title>
273
<programlisting>void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
274
<link linkend="gint">gint</link> arg1,
275
<link linkend="gint">gint</link> arg2,
276
<link linkend="gint">gint</link> arg3,
277
<link linkend="gint">gint</link> arg4,
278
<link linkend="gpointer">gpointer</link> user_data);</programlisting>
280
This signal is emitted when a significant area of the image being
281
loaded has been updated. Normally it means that a complete
282
scanline has been read in, but it could be a different area as
283
well. Applications can use this signal to know when to repaint
284
areas of an image that is being loaded.
285
</para><informaltable pgwide=1 frame="none" role="params">
287
<colspec colwidth="2*">
288
<colspec colwidth="8*">
290
<row><entry align="right"><parameter>gdkpixbufloader</parameter> :</entry>
291
<entry>the object which received the signal.
293
<row><entry align="right"><parameter>arg1</parameter> :</entry>
296
<row><entry align="right"><parameter>arg2</parameter> :</entry>
299
<row><entry align="right"><parameter>arg3</parameter> :</entry>
302
<row><entry align="right"><parameter>arg4</parameter> :</entry>
305
<row><entry align="right"><parameter>user_data</parameter> :</entry>
306
<entry>user data set when the signal handler was connected.</entry></row>
307
</tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="GdkPixbufLoader-area-prepared">The "area-prepared" signal</title>
308
<programlisting>void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
309
<link linkend="gpointer">gpointer</link> user_data);</programlisting>
311
This signal is emitted when the pixbuf loader has been fed the
312
initial amount of data that is required to figure out the size and
313
format of the image that it will create. After this signal is
314
emitted, applications can call <link linkend="gdk-pixbuf-loader-get-pixbuf">gdk_pixbuf_loader_get_pixbuf</link>() to
315
fetch the partially-loaded pixbuf.
316
</para><informaltable pgwide=1 frame="none" role="params">
318
<colspec colwidth="2*">
319
<colspec colwidth="8*">
321
<row><entry align="right"><parameter>gdkpixbufloader</parameter> :</entry>
322
<entry>the object which received the signal.
324
<row><entry align="right"><parameter>user_data</parameter> :</entry>
325
<entry>user data set when the signal handler was connected.</entry></row>
326
</tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="GdkPixbufLoader-frame-done">The "frame-done" signal</title>
327
<programlisting>void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
328
<link linkend="gpointer">gpointer</link> arg1,
329
<link linkend="gpointer">gpointer</link> user_data);</programlisting>
331
This signal is emitted when a frame is done loading. It will be
332
emitted for each frame in an animation data stream.
333
</para><informaltable pgwide=1 frame="none" role="params">
335
<colspec colwidth="2*">
336
<colspec colwidth="8*">
338
<row><entry align="right"><parameter>gdkpixbufloader</parameter> :</entry>
339
<entry>the object which received the signal.
341
<row><entry align="right"><parameter>arg1</parameter> :</entry>
344
<row><entry align="right"><parameter>user_data</parameter> :</entry>
345
<entry>user data set when the signal handler was connected.</entry></row>
346
</tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="GdkPixbufLoader-animation-done">The "animation-done" signal</title>
347
<programlisting>void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
348
<link linkend="gpointer">gpointer</link> user_data);</programlisting>
350
This signal is emitted when an animation is done loading.
351
</para><informaltable pgwide=1 frame="none" role="params">
353
<colspec colwidth="2*">
354
<colspec colwidth="8*">
356
<row><entry align="right"><parameter>gdkpixbufloader</parameter> :</entry>
357
<entry>the object which received the signal.
359
<row><entry align="right"><parameter>user_data</parameter> :</entry>
360
<entry>user data set when the signal handler was connected.</entry></row>
361
</tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="GdkPixbufLoader-closed">The "closed" signal</title>
362
<programlisting>void user_function (<link linkend="GdkPixbufLoader">GdkPixbufLoader</link> *gdkpixbufloader,
363
<link linkend="gpointer">gpointer</link> user_data);</programlisting>
365
This signal is emitted when <link linkend="gdk-pixbuf-loader-close">gdk_pixbuf_loader_close</link>() is called.
366
It can be used by different parts of an application to receive
367
notification when an image loader is closed by the code that
369
</para><informaltable pgwide=1 frame="none" role="params">
371
<colspec colwidth="2*">
372
<colspec colwidth="8*">
374
<row><entry align="right"><parameter>gdkpixbufloader</parameter> :</entry>
375
<entry>the object which received the signal.
377
<row><entry align="right"><parameter>user_data</parameter> :</entry>
378
<entry>user data set when the signal handler was connected.</entry></row>
379
</tbody></tgroup></informaltable></refsect2>
384
<title>See Also</title>
386
<link linkend="gdk-pixbuf-new-from-file">gdk_pixbuf_new_from_file</link>()