]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf-loader.c
[quartz] Delete the typedef of GdkDevicePrivate
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf-loader.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2 /* GdkPixbuf library - Progressive loader object
3  *
4  * Copyright (C) 1999 The Free Software Foundation
5  *
6  * Authors: Mark Crichton <crichton@gimp.org>
7  *          Miguel de Icaza <miguel@gnu.org>
8  *          Federico Mena-Quintero <federico@gimp.org>
9  *          Jonathan Blandford <jrb@redhat.com>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  */
26
27 #include "config.h"
28 #include <string.h>
29
30 #include "gdk-pixbuf-private.h"
31 #include "gdk-pixbuf-animation.h"
32 #include "gdk-pixbuf-scaled-anim.h"
33 #include "gdk-pixbuf-io.h"
34 #include "gdk-pixbuf-loader.h"
35 #include "gdk-pixbuf-marshal.h"
36 #include "gdk-pixbuf-alias.h"
37
38 enum {
39         SIZE_PREPARED,
40         AREA_PREPARED,
41         AREA_UPDATED,
42         CLOSED,
43         LAST_SIGNAL
44 };
45
46
47 static void gdk_pixbuf_loader_finalize (GObject *loader);
48
49 static guint    pixbuf_loader_signals[LAST_SIGNAL] = { 0 };
50
51 /* Internal data */
52
53 #define LOADER_HEADER_SIZE 1024
54
55 typedef struct
56 {
57         GdkPixbufAnimation *animation;
58         gboolean closed;
59         gboolean holds_threadlock;
60         guchar header_buf[LOADER_HEADER_SIZE];
61         gint header_buf_offset;
62         GdkPixbufModule *image_module;
63         gpointer context;
64         gint width;
65         gint height;
66         gboolean size_fixed;
67         gboolean needs_scale;
68 } GdkPixbufLoaderPrivate;
69
70 G_DEFINE_TYPE (GdkPixbufLoader, gdk_pixbuf_loader, G_TYPE_OBJECT)
71
72 static void
73 gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *class)
74 {
75         GObjectClass *object_class;
76   
77         object_class = (GObjectClass *) class;
78   
79         object_class->finalize = gdk_pixbuf_loader_finalize;
80
81         /**
82          * GdkPixbufLoader::size-prepared:
83          * @loader: the object which received the signal.
84          * @width: the original width of the image
85          * @height: the original height of the image
86          *
87          * This signal is emitted when the pixbuf loader has been fed the
88          * initial amount of data that is required to figure out the size
89          * of the image that it will create.  Applications can call  
90          * gdk_pixbuf_loader_set_size() in response to this signal to set
91          * the desired size to which the image should be scaled.
92          */
93         pixbuf_loader_signals[SIZE_PREPARED] =
94                 g_signal_new ("size-prepared",
95                               G_TYPE_FROM_CLASS (object_class),
96                               G_SIGNAL_RUN_LAST,
97                               G_STRUCT_OFFSET (GdkPixbufLoaderClass, size_prepared),
98                               NULL, NULL,
99                               _gdk_pixbuf_marshal_VOID__INT_INT,
100                               G_TYPE_NONE, 2, 
101                               G_TYPE_INT,
102                               G_TYPE_INT);
103   
104         /**
105          * GdkPixbufLoader::area-prepared:
106          * @loader: the object which received the signal.
107          *
108          * This signal is emitted when the pixbuf loader has allocated the 
109          * pixbuf in the desired size.  After this signal is emitted, 
110          * applications can call gdk_pixbuf_loader_get_pixbuf() to fetch 
111          * the partially-loaded pixbuf.
112          */
113         pixbuf_loader_signals[AREA_PREPARED] =
114                 g_signal_new ("area-prepared",
115                               G_TYPE_FROM_CLASS (object_class),
116                               G_SIGNAL_RUN_LAST,
117                               G_STRUCT_OFFSET (GdkPixbufLoaderClass, area_prepared),
118                               NULL, NULL,
119                               _gdk_pixbuf_marshal_VOID__VOID,
120                               G_TYPE_NONE, 0);
121
122         /**
123          * GdkPixbufLoader::area-updated:
124          * @loader: the object which received the signal.
125          * @x: X offset of upper-left corner of the updated area.
126          * @y: Y offset of upper-left corner of the updated area.
127          * @width: Width of updated area.
128          * @height: Height of updated area.
129          *
130          * This signal is emitted when a significant area of the image being
131          * loaded has been updated.  Normally it means that a complete
132          * scanline has been read in, but it could be a different area as
133          * well.  Applications can use this signal to know when to repaint
134          * areas of an image that is being loaded.
135          */
136         pixbuf_loader_signals[AREA_UPDATED] =
137                 g_signal_new ("area-updated",
138                               G_TYPE_FROM_CLASS (object_class),
139                               G_SIGNAL_RUN_LAST,
140                               G_STRUCT_OFFSET (GdkPixbufLoaderClass, area_updated),
141                               NULL, NULL,
142                               _gdk_pixbuf_marshal_VOID__INT_INT_INT_INT,
143                               G_TYPE_NONE, 4,
144                               G_TYPE_INT,
145                               G_TYPE_INT,
146                               G_TYPE_INT,
147                               G_TYPE_INT);
148   
149         /**
150          * GdkPixbufLoader::closed:
151          * @loader: the object which received the signal.
152          *
153          * This signal is emitted when gdk_pixbuf_loader_close() is called.
154          * It can be used by different parts of an application to receive
155          * notification when an image loader is closed by the code that
156          * drives it.
157          */
158         pixbuf_loader_signals[CLOSED] =
159                 g_signal_new ("closed",
160                               G_TYPE_FROM_CLASS (object_class),
161                               G_SIGNAL_RUN_LAST,
162                               G_STRUCT_OFFSET (GdkPixbufLoaderClass, closed),
163                               NULL, NULL,
164                               _gdk_pixbuf_marshal_VOID__VOID,
165                               G_TYPE_NONE, 0);
166 }
167
168 static void
169 gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
170 {
171         GdkPixbufLoaderPrivate *priv;
172   
173         priv = g_new0 (GdkPixbufLoaderPrivate, 1);
174         priv->width = -1;
175         priv->height = -1;
176
177         loader->priv = priv;
178 }
179
180 static void
181 gdk_pixbuf_loader_finalize (GObject *object)
182 {
183         GdkPixbufLoader *loader;
184         GdkPixbufLoaderPrivate *priv = NULL;
185   
186         loader = GDK_PIXBUF_LOADER (object);
187         priv = loader->priv;
188
189         if (!priv->closed) {
190                 g_warning ("GdkPixbufLoader finalized without calling gdk_pixbuf_loader_close() - this is not allowed. You must explicitly end the data stream to the loader before dropping the last reference.");
191                 if (priv->holds_threadlock) {
192                         _gdk_pixbuf_unlock (priv->image_module);
193                 }
194         }
195         if (priv->animation)
196                 g_object_unref (priv->animation);
197   
198         g_free (priv);
199   
200         G_OBJECT_CLASS (gdk_pixbuf_loader_parent_class)->finalize (object);
201 }
202
203 /**
204  * gdk_pixbuf_loader_set_size:
205  * @loader: A pixbuf loader.
206  * @width: The desired width of the image being loaded.
207  * @height: The desired height of the image being loaded.
208  *
209  * Causes the image to be scaled while it is loaded. The desired
210  * image size can be determined relative to the original size of
211  * the image by calling gdk_pixbuf_loader_set_size() from a
212  * signal handler for the ::size-prepared signal.
213  *
214  * Attempts to set the desired image size  are ignored after the 
215  * emission of the ::size-prepared signal.
216  *
217  * Since: 2.2
218  */
219 void 
220 gdk_pixbuf_loader_set_size (GdkPixbufLoader *loader,
221                             gint             width,
222                             gint             height)
223 {
224         GdkPixbufLoaderPrivate *priv;
225
226         g_return_if_fail (GDK_IS_PIXBUF_LOADER (loader));
227         g_return_if_fail (width >= 0 && height >= 0);
228
229         priv = GDK_PIXBUF_LOADER (loader)->priv;
230
231         if (!priv->size_fixed) 
232                 {
233                         priv->width = width;
234                         priv->height = height;
235                 }
236 }
237
238 static void
239 gdk_pixbuf_loader_size_func (gint *width, gint *height, gpointer loader)
240 {
241         GdkPixbufLoaderPrivate *priv = GDK_PIXBUF_LOADER (loader)->priv;
242
243         /* allow calling gdk_pixbuf_loader_set_size() before the signal */
244         if (priv->width == -1 && priv->height == -1) 
245                 {
246                         priv->width = *width;
247                         priv->height = *height;
248                 }
249
250         g_signal_emit (loader, pixbuf_loader_signals[SIZE_PREPARED], 0, *width, *height);
251         priv->size_fixed = TRUE;
252
253         *width = priv->width;
254         *height = priv->height;
255 }
256
257 static void
258 gdk_pixbuf_loader_prepare (GdkPixbuf          *pixbuf,
259                            GdkPixbufAnimation *anim,
260                            gpointer            loader)
261 {
262         GdkPixbufLoaderPrivate *priv = GDK_PIXBUF_LOADER (loader)->priv;
263         g_return_if_fail (pixbuf != NULL);
264
265         if (!priv->size_fixed) 
266                 {
267                         /* Defend against lazy loaders which don't call size_func */
268                         gint width = gdk_pixbuf_get_width (pixbuf);
269                         gint height = gdk_pixbuf_get_height (pixbuf);
270                         
271                         gdk_pixbuf_loader_size_func (&width, &height, loader);
272                 }
273
274         priv->needs_scale = FALSE;
275         if (priv->width > 0 && priv->height > 0 &&
276             (priv->width != gdk_pixbuf_get_width (pixbuf) ||
277              priv->height != gdk_pixbuf_get_height (pixbuf)))
278                 priv->needs_scale = TRUE;
279
280         if (anim)
281                 g_object_ref (anim);
282         else
283                 anim = gdk_pixbuf_non_anim_new (pixbuf);
284   
285         if (priv->needs_scale) {
286                 priv->animation  = GDK_PIXBUF_ANIMATION (_gdk_pixbuf_scaled_anim_new (anim,
287                                          (double) priv->width / gdk_pixbuf_get_width (pixbuf),
288                                          (double) priv->height / gdk_pixbuf_get_height (pixbuf),
289                                           1.0));
290                         g_object_unref (anim);
291         }
292         else
293                 priv->animation = anim;
294   
295         if (!priv->needs_scale)
296                 g_signal_emit (loader, pixbuf_loader_signals[AREA_PREPARED], 0);
297 }
298
299 static void
300 gdk_pixbuf_loader_update (GdkPixbuf *pixbuf,
301                           gint       x,
302                           gint       y,
303                           gint       width,
304                           gint       height,
305                           gpointer   loader)
306 {
307         GdkPixbufLoaderPrivate *priv = GDK_PIXBUF_LOADER (loader)->priv;
308   
309         if (!priv->needs_scale)
310                 g_signal_emit (loader,
311                                pixbuf_loader_signals[AREA_UPDATED],
312                                0,
313                                x, y,
314                                /* sanity check in here.  Defend against an errant loader */
315                                MIN (width, gdk_pixbuf_animation_get_width (priv->animation)),
316                                MIN (height, gdk_pixbuf_animation_get_height (priv->animation)));
317 }
318
319 /* Defense against broken loaders; DO NOT take this as a GError example! */
320 static void
321 gdk_pixbuf_loader_ensure_error (GdkPixbufLoader *loader,
322                                 GError         **error)
323
324         GdkPixbufLoaderPrivate *priv = loader->priv;
325
326         if (error == NULL || *error != NULL)
327                 return;
328
329         g_warning ("Bug! loader '%s' didn't set an error on failure",
330                    priv->image_module->module_name);
331         g_set_error (error,
332                      GDK_PIXBUF_ERROR,
333                      GDK_PIXBUF_ERROR_FAILED,
334                      _("Internal error: Image loader module '%s' failed to"
335                        " complete an operation, but didn't give a reason for"
336                        " the failure"),
337                      priv->image_module->module_name);
338 }
339
340 static gint
341 gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
342                                const char      *image_type,
343                                GError         **error)
344 {
345         GdkPixbufLoaderPrivate *priv = loader->priv;
346
347         if (image_type)
348                 {
349                         priv->image_module = _gdk_pixbuf_get_named_module (image_type,
350                                                                            error);
351                 }
352         else
353                 {
354                         priv->image_module = _gdk_pixbuf_get_module (priv->header_buf,
355                                                                      priv->header_buf_offset,
356                                                                      NULL,
357                                                                      error);
358                 }
359   
360         if (priv->image_module == NULL)
361                 return 0;
362   
363         if (!_gdk_pixbuf_load_module (priv->image_module, error))
364                 return 0;
365   
366         if (priv->image_module->module == NULL)
367                 return 0;
368   
369         if ((priv->image_module->begin_load == NULL) ||
370             (priv->image_module->stop_load == NULL) ||
371             (priv->image_module->load_increment == NULL))
372                 {
373                         g_set_error (error,
374                                      GDK_PIXBUF_ERROR,
375                                      GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
376                                      _("Incremental loading of image type '%s' is not supported"),
377                                      priv->image_module->module_name);
378
379                         return 0;
380                 }
381
382         if (!priv->holds_threadlock) {
383                 priv->holds_threadlock = _gdk_pixbuf_lock (priv->image_module);
384         }
385
386         priv->context = priv->image_module->begin_load (gdk_pixbuf_loader_size_func,
387                                                         gdk_pixbuf_loader_prepare,
388                                                         gdk_pixbuf_loader_update,
389                                                         loader,
390                                                         error);
391   
392         if (priv->context == NULL)
393                 {
394                         gdk_pixbuf_loader_ensure_error (loader, error);
395                         return 0;
396                 }
397   
398         if (priv->header_buf_offset
399             && priv->image_module->load_increment (priv->context, priv->header_buf, priv->header_buf_offset, error))
400                 return priv->header_buf_offset;
401   
402         return 0;
403 }
404
405 static int
406 gdk_pixbuf_loader_eat_header_write (GdkPixbufLoader *loader,
407                                     const guchar    *buf,
408                                     gsize            count,
409                                     GError         **error)
410 {
411         gint n_bytes;
412         GdkPixbufLoaderPrivate *priv = loader->priv;
413   
414         n_bytes = MIN(LOADER_HEADER_SIZE - priv->header_buf_offset, count);
415         memcpy (priv->header_buf + priv->header_buf_offset, buf, n_bytes);
416   
417         priv->header_buf_offset += n_bytes;
418   
419         if (priv->header_buf_offset >= LOADER_HEADER_SIZE)
420                 {
421                         if (gdk_pixbuf_loader_load_module (loader, NULL, error) == 0)
422                                 return 0;
423                 }
424   
425         return n_bytes;
426 }
427
428 /**
429  * gdk_pixbuf_loader_write:
430  * @loader: A pixbuf loader.
431  * @buf: Pointer to image data.
432  * @count: Length of the @buf buffer in bytes.
433  * @error: return location for errors
434  *
435  * This will cause a pixbuf loader to parse the next @count bytes of
436  * an image.  It will return %TRUE if the data was loaded successfully,
437  * and %FALSE if an error occurred.  In the latter case, the loader
438  * will be closed, and will not accept further writes. If %FALSE is
439  * returned, @error will be set to an error from the #GDK_PIXBUF_ERROR
440  * or #G_FILE_ERROR domains.
441  *
442  * Return value: %TRUE if the write was successful, or %FALSE if the loader
443  * cannot parse the buffer.
444  **/
445 gboolean
446 gdk_pixbuf_loader_write (GdkPixbufLoader *loader,
447                          const guchar    *buf,
448                          gsize            count,
449                          GError         **error)
450 {
451         GdkPixbufLoaderPrivate *priv;
452   
453         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), FALSE);
454   
455         g_return_val_if_fail (buf != NULL, FALSE);
456         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
457   
458         priv = loader->priv;
459
460         /* we expect it's not to be closed */
461         g_return_val_if_fail (priv->closed == FALSE, FALSE);
462   
463         if (count > 0 && priv->image_module == NULL)
464                 {
465                         gint eaten;
466       
467                         eaten = gdk_pixbuf_loader_eat_header_write (loader, buf, count, error);
468                         if (eaten <= 0)
469                                goto fail; 
470       
471                         count -= eaten;
472                         buf += eaten;
473                 }
474   
475         if (count > 0 && priv->image_module->load_increment)
476                 {
477                         if (!priv->image_module->load_increment (priv->context, buf, count,
478                                                                  error))
479                                 goto fail;
480                 }
481       
482         return TRUE;
483
484  fail:
485         gdk_pixbuf_loader_ensure_error (loader, error);
486         gdk_pixbuf_loader_close (loader, NULL);
487
488         return FALSE;
489 }
490
491 /**
492  * gdk_pixbuf_loader_new:
493  *
494  * Creates a new pixbuf loader object.
495  *
496  * Return value: A newly-created pixbuf loader.
497  **/
498 GdkPixbufLoader *
499 gdk_pixbuf_loader_new (void)
500 {
501         return g_object_new (GDK_TYPE_PIXBUF_LOADER, NULL);
502 }
503
504 /**
505  * gdk_pixbuf_loader_new_with_type:
506  * @image_type: name of the image format to be loaded with the image
507  * @error: (allow-none): return location for an allocated #GError, or %NULL to ignore errors
508  *
509  * Creates a new pixbuf loader object that always attempts to parse
510  * image data as if it were an image of type @image_type, instead of
511  * identifying the type automatically. Useful if you want an error if
512  * the image isn't the expected type, for loading image formats
513  * that can't be reliably identified by looking at the data, or if
514  * the user manually forces a specific type.
515  *
516  * The list of supported image formats depends on what image loaders
517  * are installed, but typically "png", "jpeg", "gif", "tiff" and 
518  * "xpm" are among the supported formats. To obtain the full list of
519  * supported image formats, call gdk_pixbuf_format_get_name() on each 
520  * of the #GdkPixbufFormat structs returned by gdk_pixbuf_get_formats().
521  *
522  * Return value: A newly-created pixbuf loader.
523  **/
524 GdkPixbufLoader *
525 gdk_pixbuf_loader_new_with_type (const char *image_type,
526                                  GError    **error)
527 {
528         GdkPixbufLoader *retval;
529         GError *tmp;
530         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
531   
532         retval = g_object_new (GDK_TYPE_PIXBUF_LOADER, NULL);
533
534         tmp = NULL;
535         gdk_pixbuf_loader_load_module (retval, image_type, &tmp);
536         if (tmp != NULL)
537                 {
538                         g_propagate_error (error, tmp);
539                         gdk_pixbuf_loader_close (retval, NULL);
540                         g_object_unref (retval);
541                         return NULL;
542                 }
543
544         return retval;
545 }
546
547 /**
548  * gdk_pixbuf_loader_new_with_mime_type:
549  * @mime_type: the mime type to be loaded 
550  * @error: (allow-none): return location for an allocated #GError, or %NULL to ignore errors
551  *
552  * Creates a new pixbuf loader object that always attempts to parse
553  * image data as if it were an image of mime type @mime_type, instead of
554  * identifying the type automatically. Useful if you want an error if
555  * the image isn't the expected mime type, for loading image formats
556  * that can't be reliably identified by looking at the data, or if
557  * the user manually forces a specific mime type.
558  *
559  * The list of supported mime types depends on what image loaders
560  * are installed, but typically "image/png", "image/jpeg", "image/gif", 
561  * "image/tiff" and "image/x-xpixmap" are among the supported mime types. 
562  * To obtain the full list of supported mime types, call 
563  * gdk_pixbuf_format_get_mime_types() on each of the #GdkPixbufFormat 
564  * structs returned by gdk_pixbuf_get_formats().
565  *
566  * Return value: A newly-created pixbuf loader.
567  * Since: 2.4
568  **/
569 GdkPixbufLoader *
570 gdk_pixbuf_loader_new_with_mime_type (const char *mime_type,
571                                       GError    **error)
572 {
573         const char * image_type = NULL;
574         char ** mimes;
575
576         GdkPixbufLoader *retval;
577         GError *tmp;
578   
579         GSList * formats;
580         GdkPixbufFormat *info;
581         int i, j, length;
582
583         formats = gdk_pixbuf_get_formats ();
584         length = g_slist_length (formats);
585
586         for (i = 0; i < length && image_type == NULL; i++) {
587                 info = (GdkPixbufFormat *)g_slist_nth_data (formats, i);
588                 mimes = info->mime_types;
589                 
590                 for (j = 0; mimes[j] != NULL; j++)
591                         if (g_ascii_strcasecmp (mimes[j], mime_type) == 0) {
592                                 image_type = info->name;
593                                 break;
594                         }
595         }
596
597         g_slist_free (formats);
598
599         retval = g_object_new (GDK_TYPE_PIXBUF_LOADER, NULL);
600
601         tmp = NULL;
602         gdk_pixbuf_loader_load_module (retval, image_type, &tmp);
603         if (tmp != NULL)
604                 {
605                         g_propagate_error (error, tmp);
606                         gdk_pixbuf_loader_close (retval, NULL);
607                         g_object_unref (retval);
608                         return NULL;
609                 }
610
611         return retval;
612 }
613
614 /**
615  * gdk_pixbuf_loader_get_pixbuf:
616  * @loader: A pixbuf loader.
617  *
618  * Queries the #GdkPixbuf that a pixbuf loader is currently creating.
619  * In general it only makes sense to call this function after the
620  * "area-prepared" signal has been emitted by the loader; this means
621  * that enough data has been read to know the size of the image that
622  * will be allocated.  If the loader has not received enough data via
623  * gdk_pixbuf_loader_write(), then this function returns %NULL.  The
624  * returned pixbuf will be the same in all future calls to the loader,
625  * so simply calling g_object_ref() should be sufficient to continue
626  * using it.  Additionally, if the loader is an animation, it will
627  * return the "static image" of the animation
628  * (see gdk_pixbuf_animation_get_static_image()).
629  * 
630  * Return value: The #GdkPixbuf that the loader is creating, or %NULL if not
631  * enough data has been read to determine how to create the image buffer.
632  **/
633 GdkPixbuf *
634 gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader)
635 {
636         GdkPixbufLoaderPrivate *priv;
637   
638         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
639   
640         priv = loader->priv;
641
642         if (priv->animation)
643                 return gdk_pixbuf_animation_get_static_image (priv->animation);
644         else
645                 return NULL;
646 }
647
648 /**
649  * gdk_pixbuf_loader_get_animation:
650  * @loader: A pixbuf loader
651  *
652  * Queries the #GdkPixbufAnimation that a pixbuf loader is currently creating.
653  * In general it only makes sense to call this function after the "area-prepared"
654  * signal has been emitted by the loader. If the loader doesn't have enough
655  * bytes yet (hasn't emitted the "area-prepared" signal) this function will 
656  * return %NULL.
657  *
658  * Return value: The #GdkPixbufAnimation that the loader is loading, or %NULL if
659  not enough data has been read to determine the information.
660 **/
661 GdkPixbufAnimation *
662 gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader)
663 {
664         GdkPixbufLoaderPrivate *priv;
665   
666         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
667   
668         priv = loader->priv;
669   
670         return priv->animation;
671 }
672
673 /**
674  * gdk_pixbuf_loader_close:
675  * @loader: A pixbuf loader.
676  * @error: (allow-none): return location for a #GError, or %NULL to ignore errors
677  *
678  * Informs a pixbuf loader that no further writes with
679  * gdk_pixbuf_loader_write() will occur, so that it can free its
680  * internal loading structures. Also, tries to parse any data that
681  * hasn't yet been parsed; if the remaining data is partial or
682  * corrupt, an error will be returned.  If %FALSE is returned, @error
683  * will be set to an error from the #GDK_PIXBUF_ERROR or #G_FILE_ERROR
684  * domains. If you're just cancelling a load rather than expecting it
685  * to be finished, passing %NULL for @error to ignore it is
686  * reasonable.
687  *
688  * Returns: %TRUE if all image data written so far was successfully
689             passed out via the update_area signal
690  **/
691 gboolean
692 gdk_pixbuf_loader_close (GdkPixbufLoader *loader,
693                          GError         **error)
694 {
695         GdkPixbufLoaderPrivate *priv;
696         gboolean retval = TRUE;
697   
698         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), TRUE);
699         g_return_val_if_fail (error == NULL || *error == NULL, TRUE);
700   
701         priv = loader->priv;
702   
703         if (priv->closed)
704                 return TRUE;
705   
706         /* We have less the LOADER_HEADER_SIZE bytes in the image.  
707          * Flush it, and keep going. 
708          */
709         if (priv->image_module == NULL)
710                 {
711                         GError *tmp = NULL;
712                         gdk_pixbuf_loader_load_module (loader, NULL, &tmp);
713                         if (tmp != NULL)
714                                 {
715                                         g_propagate_error (error, tmp);
716                                         retval = FALSE;
717                                 }
718                 }  
719
720         if (priv->image_module && priv->image_module->stop_load && priv->context) 
721                 {
722                         GError *tmp = NULL;
723                         if (!priv->image_module->stop_load (priv->context, &tmp) || tmp)
724                                 {
725                                         /* don't call gdk_pixbuf_loader_ensure_error()
726                                          * here, since we might not get an error in the
727                                          * gdk_pixbuf_get_file_info() case
728                                          */
729                                         if (tmp) {
730                                                 if (error && *error == NULL)
731                                                         g_propagate_error (error, tmp);
732                                                 else
733                                                         g_error_free (tmp);
734                                         }
735                                         retval = FALSE;
736                                 }
737                 }
738   
739         priv->closed = TRUE;
740         if (priv->image_module && priv->holds_threadlock) {
741                 _gdk_pixbuf_unlock (priv->image_module);
742                 priv->holds_threadlock = FALSE;
743         }
744
745         if (priv->needs_scale) 
746                 {
747
748                         g_signal_emit (loader, pixbuf_loader_signals[AREA_PREPARED], 0);
749                         g_signal_emit (loader, pixbuf_loader_signals[AREA_UPDATED], 0, 
750                                        0, 0, priv->width, priv->height);
751                 }
752
753         
754         g_signal_emit (loader, pixbuf_loader_signals[CLOSED], 0);
755
756         return retval;
757 }
758
759 /**
760  * gdk_pixbuf_loader_get_format:
761  * @loader: A pixbuf loader.
762  *
763  * Obtains the available information about the format of the 
764  * currently loading image file.
765  *
766  * Returns: A #GdkPixbufFormat or %NULL. The return value is owned 
767  * by GdkPixbuf and should not be freed.
768  * 
769  * Since: 2.2
770  */
771 GdkPixbufFormat *
772 gdk_pixbuf_loader_get_format (GdkPixbufLoader *loader)
773 {
774         GdkPixbufLoaderPrivate *priv;
775   
776         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
777   
778         priv = loader->priv;
779
780         if (priv->image_module)
781                 return _gdk_pixbuf_get_format (priv->image_module);
782         else
783                 return NULL;
784 }
785
786
787 #define __GDK_PIXBUF_LOADER_C__
788 #include "gdk-pixbuf-aliasdef.c"
789