I've no idea here...
[gtkD.git] / src / gdkpixbuf / PixbufLoader.d
blob63533ac90caa542030abf2a3e1ac8e90f5829abe
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GdkPixbufLoader.html
26 * outPack = gdkpixbuf
27 * outFile = PixbufLoader
28 * strct = GdkPixbufLoader
29 * realStrct=
30 * ctorStrct=
31 * clss = PixbufLoader
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gdk_pixbuf_loader_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * - gdk_pixbuf_loader_new_with_type
44 * - gdk_pixbuf_loader_new_with_mime_type
45 * imports:
46 * - gdkpixbuf.PixbufFormat
47 * - gdk.Pixbuf
48 * - gdkpixbuf.PixbufAnimation
49 * - glib.Str
50 * structWrap:
51 * - GdkPixbuf* -> Pixbuf
52 * - GdkPixbufAnimation* -> PixbufAnimation
53 * - GdkPixbufFormat* -> PixbufFormat
54 * local aliases:
57 module gdkpixbuf.PixbufLoader;
59 private import gdkpixbuf.gdkpixbuftypes;
61 private import lib.gdkpixbuf;
63 private import gdkpixbuf.PixbufFormat;
64 private import gdk.Pixbuf;
65 private import gdkpixbuf.PixbufAnimation;
66 private import glib.Str;
68 /**
69 * Description
70 * GdkPixbufLoader provides a way for applications to drive the
71 * process of loading an image, by letting them send the image data
72 * directly to the loader instead of having the loader read the data
73 * from a file. Applications can use this functionality instead of
74 * gdk_pixbuf_new_from_file() or gdk_pixbuf_animation_new_from_file()
75 * when they need to parse image data in
76 * small chunks. For example, it should be used when reading an
77 * image from a (potentially) slow network connection, or when
78 * loading an extremely large file.
79 * To use GdkPixbufLoader to load an image, just create a new one,
80 * and call gdk_pixbuf_loader_write() to send the data to it. When
81 * done, gdk_pixbuf_loader_close() should be called to end the stream
82 * and finalize everything. The loader will emit three important
83 * signals throughout the process. The first, "size_prepared",
84 * will be called as soon as the image has enough information to
85 * determine the size of the image to be used. If you want to scale
86 * the image while loading it, you can call gdk_pixbuf_loader_set_size()
87 * in response to this signal.
88 * The second signal, "area_prepared",
89 * will be called as soon as the pixbuf of the desired has been
90 * allocated. You can obtain it by calling gdk_pixbuf_loader_get_pixbuf().
91 * If you want to use it, simply ref it.
92 * In addition, no actual information will be passed in yet, so the
93 * pixbuf can be safely filled with any temporary graphics (or an
94 * initial color) as needed. You can also call
95 * gdk_pixbuf_loader_get_pixbuf() later and get the same pixbuf.
96 * The last signal, "area_updated" gets
97 * called every time a region is updated. This way you can update a
98 * partially completed image. Note that you do not know anything
99 * about the completeness of an image from the area updated. For
100 * example, in an interlaced image, you need to make several passes
101 * before the image is done loading.
102 * Loading an animation
103 * Loading an animation is almost as easy as loading an
104 * image. Once the first "area_prepared" signal
105 * has been emitted, you can call gdk_pixbuf_loader_get_animation()
106 * to get the GdkPixbufAnimation struct and gdk_pixbuf_animation_get_iter()
107 * to get an GdkPixbufAnimationIter for displaying it.
109 private import gobject.ObjectG;
110 public class PixbufLoader : ObjectG
113 /** the main Gtk struct */
114 protected GdkPixbufLoader* gdkPixbufLoader;
117 public GdkPixbufLoader* getPixbufLoaderStruct()
119 return gdkPixbufLoader;
123 /** the main Gtk struct as a void* */
124 protected void* getStruct()
126 return cast(void*)gdkPixbufLoader;
130 * Sets our main struct and passes it to the parent class
132 public this (GdkPixbufLoader* gdkPixbufLoader)
134 super(cast(GObject*)gdkPixbufLoader);
135 this.gdkPixbufLoader = gdkPixbufLoader;
139 * Creates a new pixbuf loader object that always attempts to parse
140 * image data as if it were an image of type image_type or mime_type, instead of
141 * identifying the type automatically. Useful if you want an error if
142 * the image isn't the expected type, for loading image formats
143 * that can't be reliably identified by looking at the data, or if
144 * the user manually forces a specific type.
145 * type:
146 * name of the image format or mime to be loaded with the image
147 * error:
148 * return location for an allocated GError, or NULL to ignore errors
149 * Returns:
150 * A newly-created pixbuf loader.
152 public this (char[] type, GError** error, bit isMimeType=false)
154 if ( isMimeType )
156 // GdkPixbufLoader* gdk_pixbuf_loader_new_with_mime_type (const char *mime_type, GError **error);
157 this(cast(GdkPixbufLoader*)gdk_pixbuf_loader_new_with_mime_type(Str.toStringz(type), error) );
159 else
161 // GdkPixbufLoader* gdk_pixbuf_loader_new_with_type (const char *image_type, GError **error);
162 this(cast(GdkPixbufLoader*)gdk_pixbuf_loader_new_with_type(Str.toStringz(type), error) );
169 // imports for the signal processing
170 private import gobject.Signals;
171 private import gdk.gdktypes;
172 int[char[]] connectedSignals;
174 void delegate(PixbufLoader)[] onAreaPreparedListeners;
175 void addOnAreaPrepared(void delegate(PixbufLoader) dlg)
177 if ( !("area-prepared" in connectedSignals) )
179 Signals.connectData(
180 getStruct(),
181 "area-prepared",
182 cast(GCallback)&callBackAreaPrepared,
183 this,
184 null,
185 cast(ConnectFlags)0);
186 connectedSignals["area-prepared"] = 1;
188 onAreaPreparedListeners ~= dlg;
190 extern(C) static void callBackAreaPrepared(GdkPixbufLoader* loaderStruct, PixbufLoader pixbufLoader)
192 bit consumed = false;
194 foreach ( void delegate(PixbufLoader) dlg ; pixbufLoader.onAreaPreparedListeners )
196 dlg(pixbufLoader);
199 return consumed;
202 void delegate(gint, gint, gint, gint, PixbufLoader)[] onAreaUpdatedListeners;
203 void addOnAreaUpdated(void delegate(gint, gint, gint, gint, PixbufLoader) dlg)
205 if ( !("area-updated" in connectedSignals) )
207 Signals.connectData(
208 getStruct(),
209 "area-updated",
210 cast(GCallback)&callBackAreaUpdated,
211 this,
212 null,
213 cast(ConnectFlags)0);
214 connectedSignals["area-updated"] = 1;
216 onAreaUpdatedListeners ~= dlg;
218 extern(C) static void callBackAreaUpdated(GdkPixbufLoader* loaderStruct, gint x, gint y, gint width, gint height, PixbufLoader pixbufLoader)
220 bit consumed = false;
222 foreach ( void delegate(gint, gint, gint, gint, PixbufLoader) dlg ; pixbufLoader.onAreaUpdatedListeners )
224 dlg(x, y, width, height, pixbufLoader);
227 return consumed;
230 void delegate(PixbufLoader)[] onClosedListeners;
231 void addOnClosed(void delegate(PixbufLoader) dlg)
233 if ( !("closed" in connectedSignals) )
235 Signals.connectData(
236 getStruct(),
237 "closed",
238 cast(GCallback)&callBackClosed,
239 this,
240 null,
241 cast(ConnectFlags)0);
242 connectedSignals["closed"] = 1;
244 onClosedListeners ~= dlg;
246 extern(C) static void callBackClosed(GdkPixbufLoader* loaderStruct, PixbufLoader pixbufLoader)
248 bit consumed = false;
250 foreach ( void delegate(PixbufLoader) dlg ; pixbufLoader.onClosedListeners )
252 dlg(pixbufLoader);
255 return consumed;
258 void delegate(gint, gint, PixbufLoader)[] onSizePreparedListeners;
259 void addOnSizePrepared(void delegate(gint, gint, PixbufLoader) dlg)
261 if ( !("size-prepared" in connectedSignals) )
263 Signals.connectData(
264 getStruct(),
265 "size-prepared",
266 cast(GCallback)&callBackSizePrepared,
267 this,
268 null,
269 cast(ConnectFlags)0);
270 connectedSignals["size-prepared"] = 1;
272 onSizePreparedListeners ~= dlg;
274 extern(C) static void callBackSizePrepared(GdkPixbufLoader* loaderStruct, gint width, gint height, PixbufLoader pixbufLoader)
276 bit consumed = false;
278 foreach ( void delegate(gint, gint, PixbufLoader) dlg ; pixbufLoader.onSizePreparedListeners )
280 dlg(width, height, pixbufLoader);
283 return consumed;
289 * Creates a new pixbuf loader object.
290 * Returns:
291 * A newly-created pixbuf loader.
293 public this ()
295 // GdkPixbufLoader* gdk_pixbuf_loader_new (void);
296 this(cast(GdkPixbufLoader*)gdk_pixbuf_loader_new() );
302 * Obtains the available information about the format of the
303 * currently loading image file.
304 * loader:
305 * A pixbuf loader.
306 * Returns:
307 * A GdkPixbufFormat or NULL. The return value is owned
308 * by GdkPixbuf and should not be freed.
309 * Since 2.2
311 public PixbufFormat getFormat()
313 // GdkPixbufFormat* gdk_pixbuf_loader_get_format (GdkPixbufLoader *loader);
314 return new PixbufFormat( gdk_pixbuf_loader_get_format(gdkPixbufLoader) );
318 * This will cause a pixbuf loader to parse the next count bytes of
319 * an image. It will return TRUE if the data was loaded successfully,
320 * and FALSE if an error occurred. In the latter case, the loader
321 * will be closed, and will not accept further writes. If FALSE is
322 * returned, error will be set to an error from the GDK_PIXBUF_ERROR
323 * or G_FILE_ERROR domains.
324 * loader:
325 * A pixbuf loader.
326 * buf:
327 * Pointer to image data.
328 * count:
329 * Length of the buf buffer in bytes.
330 * error:
331 * return location for errors
332 * Returns:
333 * TRUE if the write was successful, or FALSE if the loader
334 * cannot parse the buffer.
336 public int write(char* buf, uint count, GError** error)
338 // gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, const guchar *buf, gsize count, GError **error);
339 return gdk_pixbuf_loader_write(gdkPixbufLoader, buf, count, error);
343 * Causes the image to be scaled while it is loaded. The desired
344 * image size can be determined relative to the original size of
345 * the image by calling gdk_pixbuf_loader_set_size() from a
346 * signal handler for the ::size_prepared signal.
347 * Attempts to set the desired image size are ignored after the
348 * emission of the ::size_prepared signal.
349 * loader:
350 * A pixbuf loader.
351 * width:
352 * The desired width of the image being loaded.
353 * height:
354 * The desired height of the image being loaded.
355 * Since 2.2
357 public void setSize(int width, int height)
359 // void gdk_pixbuf_loader_set_size (GdkPixbufLoader *loader, int width, int height);
360 gdk_pixbuf_loader_set_size(gdkPixbufLoader, width, height);
364 * Queries the GdkPixbuf that a pixbuf loader is currently creating.
365 * In general it only makes sense to call this function after the
366 * "area_prepared" signal has been emitted by the loader; this means
367 * that enough data has been read to know the size of the image that
368 * will be allocated. If the loader has not received enough data via
369 * gdk_pixbuf_loader_write(), then this function returns NULL. The
370 * returned pixbuf will be the same in all future calls to the loader,
371 * so simply calling g_object_ref() should be sufficient to continue
372 * using it. Additionally, if the loader is an animation, it will
373 * return the "static image" of the animation
374 * (see gdk_pixbuf_animation_get_static_image()).
375 * loader:
376 * A pixbuf loader.
377 * Returns:
378 * The GdkPixbuf that the loader is creating, or NULL if not
379 * enough data has been read to determine how to create the image buffer.
381 public Pixbuf getPixbuf()
383 // GdkPixbuf* gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader);
384 return new Pixbuf( gdk_pixbuf_loader_get_pixbuf(gdkPixbufLoader) );
388 * Queries the GdkPixbufAnimation that a pixbuf loader is currently creating.
389 * In general it only makes sense to call this function after the "area_prepared"
390 * signal has been emitted by the loader. If the loader doesn't have enough
391 * bytes yet (hasn't emitted the "area_prepared" signal) this function will
392 * return NULL.
393 * loader:
394 * A pixbuf loader
395 * Returns:
396 * The GdkPixbufAnimation that the loader is loading, or NULL if
397 * not enough data has been read to determine the information.
399 public PixbufAnimation getAnimation()
401 // GdkPixbufAnimation* gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader);
402 return new PixbufAnimation( gdk_pixbuf_loader_get_animation(gdkPixbufLoader) );
406 * Informs a pixbuf loader that no further writes with
407 * gdk_pixbuf_loader_write() will occur, so that it can free its
408 * internal loading structures. Also, tries to parse any data that
409 * hasn't yet been parsed; if the remaining data is partial or
410 * corrupt, an error will be returned. If FALSE is returned, error
411 * will be set to an error from the GDK_PIXBUF_ERROR or G_FILE_ERROR
412 * domains. If you're just cancelling a load rather than expecting it
413 * to be finished, passing NULL for error to ignore it is
414 * reasonable.
415 * loader:
416 * A pixbuf loader.
417 * error:
418 * return location for a GError, or NULL to ignore errors
419 * Returns:
420 * TRUE if all image data written so far was successfully
421 * passed out via the update_area signal
422 * Signal Details
423 * The "area-prepared" signal
424 * void user_function (GdkPixbufLoader *loader,
425 * gpointer user_data) : Run last
426 * This signal is emitted when the pixbuf loader has allocated the
427 * pixbuf in the desired size. After this signal is emitted,
428 * applications can call gdk_pixbuf_loader_get_pixbuf() to fetch
429 * the partially-loaded pixbuf.
430 * loader:
431 * the object which received the signal.
432 * user_data:
433 * user data set when the signal handler was connected.
435 public int close(GError** error)
437 // gboolean gdk_pixbuf_loader_close (GdkPixbufLoader *loader, GError **error);
438 return gdk_pixbuf_loader_close(gdkPixbufLoader, error);