]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf-loader.c
070ade1b12c4db16be839e087099152761da65b0
[~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 <string.h>
28
29 #include "gdk-pixbuf-private.h"
30 #include "gdk-pixbuf-animation.h"
31 #include "gdk-pixbuf-io.h"
32 #include "gdk-pixbuf-loader.h"
33 #include "gdk-pixbuf-marshal.h"
34
35 enum {
36         SIZE_PREPARED,
37         AREA_PREPARED,
38         AREA_UPDATED,
39         CLOSED,
40         LAST_SIGNAL
41 };
42
43
44 static void gdk_pixbuf_loader_class_init    (GdkPixbufLoaderClass   *klass);
45 static void gdk_pixbuf_loader_init          (GdkPixbufLoader        *loader);
46 static void gdk_pixbuf_loader_finalize      (GObject                *loader);
47
48 static gpointer parent_class = NULL;
49 static guint    pixbuf_loader_signals[LAST_SIGNAL] = { 0 };
50
51
52 /* Internal data */
53
54 #define LOADER_HEADER_SIZE 128
55
56 typedef struct
57 {
58         GdkPixbufAnimation *animation;
59         gboolean closed;
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
71 /**
72  * gdk_pixbuf_loader_get_type:
73  * @void:
74  *
75  * Registers the #GdkPixbufLoader class if necessary, and returns the type ID
76  * associated to it.
77  *
78  * Return value: The type ID of the #GdkPixbufLoader class.
79  **/
80 GType
81 gdk_pixbuf_loader_get_type (void)
82 {
83         static GType loader_type = 0;
84   
85         if (!loader_type)
86                 {
87                         static const GTypeInfo loader_info = {
88                                 sizeof (GdkPixbufLoaderClass),
89                                 (GBaseInitFunc) NULL,
90                                 (GBaseFinalizeFunc) NULL,
91                                 (GClassInitFunc) gdk_pixbuf_loader_class_init,
92                                 NULL,           /* class_finalize */
93                                 NULL,           /* class_data */
94                                 sizeof (GdkPixbufLoader),
95                                 0,              /* n_preallocs */
96                                 (GInstanceInitFunc) gdk_pixbuf_loader_init
97                         };
98       
99                         loader_type = g_type_register_static (G_TYPE_OBJECT,
100                                                               "GdkPixbufLoader",
101                                                               &loader_info,
102                                                               0);
103                 }
104   
105         return loader_type;
106 }
107
108 static void
109 gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *class)
110 {
111         GObjectClass *object_class;
112   
113         object_class = (GObjectClass *) class;
114   
115         parent_class = g_type_class_peek_parent (class);
116   
117         object_class->finalize = gdk_pixbuf_loader_finalize;
118
119         pixbuf_loader_signals[SIZE_PREPARED] =
120                 g_signal_new ("size_prepared",
121                               G_TYPE_FROM_CLASS (object_class),
122                               G_SIGNAL_RUN_LAST,
123                               G_STRUCT_OFFSET (GdkPixbufLoaderClass, size_prepared),
124                               NULL, NULL,
125                               gdk_pixbuf_marshal_VOID__INT_INT,
126                               G_TYPE_NONE, 2, 
127                               G_TYPE_INT,
128                               G_TYPE_INT);
129   
130         pixbuf_loader_signals[AREA_PREPARED] =
131                 g_signal_new ("area_prepared",
132                               G_TYPE_FROM_CLASS (object_class),
133                               G_SIGNAL_RUN_LAST,
134                               G_STRUCT_OFFSET (GdkPixbufLoaderClass, area_prepared),
135                               NULL, NULL,
136                               gdk_pixbuf_marshal_VOID__VOID,
137                               G_TYPE_NONE, 0);
138   
139         pixbuf_loader_signals[AREA_UPDATED] =
140                 g_signal_new ("area_updated",
141                               G_TYPE_FROM_CLASS (object_class),
142                               G_SIGNAL_RUN_LAST,
143                               G_STRUCT_OFFSET (GdkPixbufLoaderClass, area_updated),
144                               NULL, NULL,
145                               gdk_pixbuf_marshal_VOID__INT_INT_INT_INT,
146                               G_TYPE_NONE, 4,
147                               G_TYPE_INT,
148                               G_TYPE_INT,
149                               G_TYPE_INT,
150                               G_TYPE_INT);
151   
152         pixbuf_loader_signals[CLOSED] =
153                 g_signal_new ("closed",
154                               G_TYPE_FROM_CLASS (object_class),
155                               G_SIGNAL_RUN_LAST,
156                               G_STRUCT_OFFSET (GdkPixbufLoaderClass, closed),
157                               NULL, NULL,
158                               gdk_pixbuf_marshal_VOID__VOID,
159                               G_TYPE_NONE, 0);
160 }
161
162 static void
163 gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
164 {
165         GdkPixbufLoaderPrivate *priv;
166   
167         priv = g_new0 (GdkPixbufLoaderPrivate, 1);
168         loader->priv = priv;
169 }
170
171 static void
172 gdk_pixbuf_loader_finalize (GObject *object)
173 {
174         GdkPixbufLoader *loader;
175         GdkPixbufLoaderPrivate *priv = NULL;
176   
177         loader = GDK_PIXBUF_LOADER (object);
178         priv = loader->priv;
179
180         if (!priv->closed)
181                 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.");
182   
183         if (priv->animation)
184                 g_object_unref (priv->animation);
185   
186         g_free (priv);
187   
188         G_OBJECT_CLASS (parent_class)->finalize (object);
189 }
190
191 /**
192  * gdk_pixbuf_loader_set_size:
193  * @loader: A pixbuf loader.
194  * @width: The desired width of the image being loaded.
195  * @height: The desired height of the image being loaded.
196  *
197  * Causes the image to be scaled while it is loaded. The desired
198  * image size can be determined relative to the original size of
199  * the image by calling gdk_pixbuf_loader_set_size() from a
200  * signal handler for the ::size_prepared signal.
201  *
202  * Attempts to set the desired image size  are ignored after the 
203  * emission of the ::size_prepared signal.
204  */
205 void 
206 gdk_pixbuf_loader_set_size (GdkPixbufLoader *loader,
207                             gint             width,
208                             gint             height)
209 {
210         GdkPixbufLoaderPrivate *priv = GDK_PIXBUF_LOADER (loader)->priv;
211         g_return_if_fail (width > 0 && height > 0);
212
213         if (!priv->size_fixed) 
214                 {
215                         priv->width = width;
216                         priv->height = height;
217                 }
218 }
219
220 static void
221 gdk_pixbuf_loader_size_func (gint *width, gint *height, gpointer loader)
222 {
223         GdkPixbufLoaderPrivate *priv = GDK_PIXBUF_LOADER (loader)->priv;
224
225         /* allow calling gdk_pixbuf_loader_set_size() before the signal */
226         if (priv->width == 0 && priv->height == 0) 
227                 {
228                         priv->width = *width;
229                         priv->height = *height;
230                 }
231
232         g_signal_emit (loader, pixbuf_loader_signals[SIZE_PREPARED], 0, *width, *height);
233         priv->size_fixed = TRUE;
234
235         *width = priv->width;
236         *height = priv->height;
237 }
238
239 static void
240 gdk_pixbuf_loader_prepare (GdkPixbuf          *pixbuf,
241                            GdkPixbufAnimation *anim,
242                            gpointer            loader)
243 {
244         GdkPixbufLoaderPrivate *priv = GDK_PIXBUF_LOADER (loader)->priv;
245         g_return_if_fail (pixbuf != NULL);
246
247         if (!priv->size_fixed) 
248                 {
249                         /* Defend against lazy loaders which don't call size_func */
250                         gint width = gdk_pixbuf_get_width (pixbuf);
251                         gint height = gdk_pixbuf_get_height (pixbuf);
252                         
253                         gdk_pixbuf_loader_size_func (&width, &height, loader);
254                 }
255
256         priv->needs_scale = FALSE;
257         if (priv->width > 0 && priv->height > 0 &&
258             (priv->width != gdk_pixbuf_get_width (pixbuf) ||
259              priv->height != gdk_pixbuf_get_height (pixbuf)))
260                 priv->needs_scale = TRUE;
261
262         if (anim)
263                 g_object_ref (anim);
264         else
265                 anim = gdk_pixbuf_non_anim_new (pixbuf);
266   
267         priv->animation = anim;
268   
269         if (!priv->needs_scale)
270                 g_signal_emit (loader, pixbuf_loader_signals[AREA_PREPARED], 0);
271 }
272
273 static void
274 gdk_pixbuf_loader_update (GdkPixbuf *pixbuf,
275                           gint       x,
276                           gint       y,
277                           gint       width,
278                           gint       height,
279                           gpointer   loader)
280 {
281         GdkPixbufLoaderPrivate *priv = GDK_PIXBUF_LOADER (loader)->priv;
282   
283         if (!priv->needs_scale)
284                 g_signal_emit (loader,
285                                pixbuf_loader_signals[AREA_UPDATED],
286                                0,
287                                x, y,
288                                /* sanity check in here.  Defend against an errant loader */
289                                MIN (width, gdk_pixbuf_animation_get_width (priv->animation)),
290                                MIN (height, gdk_pixbuf_animation_get_height (priv->animation)));
291 }
292
293 static gint
294 gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
295                                const char      *image_type,
296                                GError         **error)
297 {
298         GdkPixbufLoaderPrivate *priv = loader->priv;
299
300         if (image_type)
301                 {
302                         priv->image_module = _gdk_pixbuf_get_named_module (image_type,
303                                                                            error);
304                 }
305         else
306                 {
307                         priv->image_module = _gdk_pixbuf_get_module (priv->header_buf,
308                                                                      priv->header_buf_offset,
309                                                                      NULL,
310                                                                      error);
311                 }
312   
313         if (priv->image_module == NULL)
314                 return 0;
315   
316         if (priv->image_module->module == NULL)
317                 if (!_gdk_pixbuf_load_module (priv->image_module, error))
318                         return 0;
319   
320         if (priv->image_module->module == NULL)
321                 return 0;
322   
323         if ((priv->image_module->begin_load == NULL) ||
324             (priv->image_module->stop_load == NULL) ||
325             (priv->image_module->load_increment == NULL))
326                 {
327                         g_set_error (error,
328                                      GDK_PIXBUF_ERROR,
329                                      GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
330                                      _("Incremental loading of image type '%s' is not supported"),
331                                      priv->image_module->module_name);
332
333                         return 0;
334                 }
335
336         priv->context = priv->image_module->begin_load (gdk_pixbuf_loader_size_func,
337                                                         gdk_pixbuf_loader_prepare,
338                                                         gdk_pixbuf_loader_update,
339                                                         loader,
340                                                         error);
341   
342         if (priv->context == NULL)
343                 {
344                         /* Defense against broken loaders; DO NOT take this as a GError
345                          * example
346                          */
347                         if (error && *error == NULL)
348                                 {
349                                         g_warning ("Bug! loader '%s' didn't set an error on failure",
350                                                    priv->image_module->module_name);
351                                         g_set_error (error,
352                                                      GDK_PIXBUF_ERROR,
353                                                      GDK_PIXBUF_ERROR_FAILED,
354                                                      _("Internal error: Image loader module '%s'"
355                                                        " failed to begin loading an image, but didn't"
356                                                        " give a reason for the failure"),
357                                                      priv->image_module->module_name);
358
359                                 }
360       
361                         return 0;
362                 }
363   
364         if (priv->header_buf_offset
365             && priv->image_module->load_increment (priv->context, priv->header_buf, priv->header_buf_offset, error))
366                 return priv->header_buf_offset;
367   
368         return 0;
369 }
370
371 static int
372 gdk_pixbuf_loader_eat_header_write (GdkPixbufLoader *loader,
373                                     const guchar    *buf,
374                                     gsize            count,
375                                     GError         **error)
376 {
377         gint n_bytes;
378         GdkPixbufLoaderPrivate *priv = loader->priv;
379   
380         n_bytes = MIN(LOADER_HEADER_SIZE - priv->header_buf_offset, count);
381         memcpy (priv->header_buf + priv->header_buf_offset, buf, n_bytes);
382   
383         priv->header_buf_offset += n_bytes;
384   
385         if (priv->header_buf_offset >= LOADER_HEADER_SIZE)
386                 {
387                         if (gdk_pixbuf_loader_load_module (loader, NULL, error) == 0)
388                                 return 0;
389                 }
390   
391         return n_bytes;
392 }
393
394 /**
395  * gdk_pixbuf_loader_write:
396  * @loader: A pixbuf loader.
397  * @buf: Pointer to image data.
398  * @count: Length of the @buf buffer in bytes.
399  * @error: return location for errors
400  *
401  * This will cause a pixbuf loader to parse the next @count bytes of
402  * an image.  It will return %TRUE if the data was loaded successfully,
403  * and %FALSE if an error occurred.  In the latter case, the loader
404  * will be closed, and will not accept further writes. If %FALSE is
405  * returned, @error will be set to an error from the #GDK_PIXBUF_ERROR
406  * or #G_FILE_ERROR domains.
407  *
408  * Return value: %TRUE if the write was successful, or %FALSE if the loader
409  * cannot parse the buffer.
410  **/
411 gboolean
412 gdk_pixbuf_loader_write (GdkPixbufLoader *loader,
413                          const guchar    *buf,
414                          gsize            count,
415                          GError         **error)
416 {
417         GdkPixbufLoaderPrivate *priv;
418   
419         g_return_val_if_fail (loader != NULL, FALSE);
420         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), FALSE);
421   
422         g_return_val_if_fail (buf != NULL, FALSE);
423         g_return_val_if_fail (count >= 0, FALSE);
424   
425         priv = loader->priv;
426
427         /* we expect it's not to be closed */
428         g_return_val_if_fail (priv->closed == FALSE, FALSE);
429   
430         if (priv->image_module == NULL)
431                 {
432                         gint eaten;
433       
434                         eaten = gdk_pixbuf_loader_eat_header_write (loader, buf, count, error);
435                         if (eaten <= 0)
436                                 return FALSE;
437       
438                         count -= eaten;
439                         buf += eaten;
440                 }
441   
442         if (count > 0 && priv->image_module->load_increment)
443                 {
444                         gboolean retval;
445                         retval = priv->image_module->load_increment (priv->context, buf, count,
446                                                                      error);
447                         if (!retval && error && *error == NULL)
448                                 {
449                                         /* Fix up busted image loader */
450                                         g_warning ("Bug! loader '%s' didn't set an error on failure",
451                                                    priv->image_module->module_name);
452                                         g_set_error (error,
453                                                      GDK_PIXBUF_ERROR,
454                                                      GDK_PIXBUF_ERROR_FAILED,
455                                                      _("Internal error: Image loader module '%s'"
456                                                        " failed to begin loading an image, but didn't"
457                                                        " give a reason for the failure"),
458                                                      priv->image_module->module_name);
459                                 }
460
461                         return retval;
462                 }
463       
464         return TRUE;
465 }
466
467 /**
468  * gdk_pixbuf_loader_new:
469  *
470  * Creates a new pixbuf loader object.
471  *
472  * Return value: A newly-created pixbuf loader.
473  **/
474 GdkPixbufLoader *
475 gdk_pixbuf_loader_new (void)
476 {
477         return g_object_new (GDK_TYPE_PIXBUF_LOADER, NULL);
478 }
479
480 /**
481  * gdk_pixbuf_loader_new_with_type:
482  * @image_type: name of the image format to be loaded with the image
483  * @error: return location for an allocated #GError, or %NULL to ignore errors
484  *
485  * Creates a new pixbuf loader object that always attempts to parse
486  * image data as if it were an image of type @image_type, instead of
487  * identifying the type automatically. Useful if you want an error if
488  * the image isn't the expected type, for loading image formats
489  * that can't be reliably identified by looking at the data, or if
490  * the user manually forces a specific type.
491  *
492  * Return value: A newly-created pixbuf loader.
493  **/
494 GdkPixbufLoader *
495 gdk_pixbuf_loader_new_with_type (const char *image_type,
496                                  GError    **error)
497 {
498         GdkPixbufLoader *retval;
499         GError *tmp;
500   
501         retval = g_object_new (GDK_TYPE_PIXBUF_LOADER, NULL);
502
503         tmp = NULL;
504         gdk_pixbuf_loader_load_module(retval, image_type, &tmp);
505         if (tmp != NULL)
506                 {
507                         g_propagate_error (error, tmp);
508                         g_object_unref (retval);
509                         return NULL;
510                 }
511
512         return retval;
513 }
514
515 /**
516  * gdk_pixbuf_loader_get_pixbuf:
517  * @loader: A pixbuf loader.
518  *
519  * Queries the #GdkPixbuf that a pixbuf loader is currently creating.
520  * In general it only makes sense to call this function after the
521  * "area_prepared" signal has been emitted by the loader; this means
522  * that enough data has been read to know the size of the image that
523  * will be allocated.  If the loader has not received enough data via
524  * gdk_pixbuf_loader_write(), then this function returns %NULL.  The
525  * returned pixbuf will be the same in all future calls to the loader,
526  * so simply calling g_object_ref() should be sufficient to continue
527  * using it.  Additionally, if the loader is an animation, it will
528  * return the "static image" of the animation
529  * (see gdk_pixbuf_animation_get_static_image()).
530  * 
531  * Return value: The #GdkPixbuf that the loader is creating, or %NULL if not
532  * enough data has been read to determine how to create the image buffer.
533  **/
534 GdkPixbuf *
535 gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader)
536 {
537         GdkPixbufLoaderPrivate *priv;
538   
539         g_return_val_if_fail (loader != NULL, NULL);
540         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
541   
542         priv = loader->priv;
543
544         if (priv->animation)
545                 return gdk_pixbuf_animation_get_static_image (priv->animation);
546         else
547                 return NULL;
548 }
549
550 /**
551  * gdk_pixbuf_loader_get_animation:
552  * @loader: A pixbuf loader
553  *
554  * Queries the #GdkPixbufAnimation that a pixbuf loader is currently creating.
555  * In general it only makes sense to call this function after the "area_prepared"
556  * signal has been emitted by the loader. If the loader doesn't have enough
557  * bytes yet (hasn't emitted the "area_prepared" signal) this function will 
558  * return %NULL.
559  *
560  * Return value: The #GdkPixbufAnimation that the loader is loading, or %NULL if
561  not enough data has been read to determine the information.
562 **/
563 GdkPixbufAnimation *
564 gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader)
565 {
566         GdkPixbufLoaderPrivate *priv;
567   
568         g_return_val_if_fail (loader != NULL, NULL);
569         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
570   
571         priv = loader->priv;
572   
573         return priv->animation;
574 }
575
576 /**
577  * gdk_pixbuf_loader_close:
578  * @loader: A pixbuf loader.
579  * @error: return location for a #GError, or %NULL to ignore errors
580  *
581  * Informs a pixbuf loader that no further writes with
582  * gdk_pixbuf_loader_write() will occur, so that it can free its
583  * internal loading structures. Also, tries to parse any data that
584  * hasn't yet been parsed; if the remaining data is partial or
585  * corrupt, an error will be returned.  If %FALSE is returned, @error
586  * will be set to an error from the #GDK_PIXBUF_ERROR or #G_FILE_ERROR
587  * domains. If you're just cancelling a load rather than expecting it
588  * to be finished, passing %NULL for @error to ignore it is
589  * reasonable.
590  *
591  * Returns: %TRUE if all image data written so far was successfully
592             passed out via the update_area signal
593  **/
594 gboolean
595 gdk_pixbuf_loader_close (GdkPixbufLoader *loader,
596                          GError         **error)
597 {
598         GdkPixbufLoaderPrivate *priv;
599         gboolean retval = TRUE;
600   
601         g_return_val_if_fail (loader != NULL, TRUE);
602         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), TRUE);
603   
604         priv = loader->priv;
605   
606         /* we expect it's not closed */
607         g_return_val_if_fail (priv->closed == FALSE, TRUE);
608   
609         /* We have less the 128 bytes in the image.  Flush it, and keep going. */
610         if (priv->image_module == NULL)
611                 {
612                         GError *tmp = NULL;
613                         gdk_pixbuf_loader_load_module (loader, NULL, &tmp);
614                         if (tmp != NULL)
615                                 {
616                                         g_propagate_error (error, tmp);
617                                         retval = FALSE;
618                                 }
619                 }  
620
621         if (priv->image_module && priv->image_module->stop_load && priv->context) 
622                 {
623                         if (!priv->image_module->stop_load (priv->context, error))
624                                 retval = FALSE;
625                 }
626   
627         priv->closed = TRUE;
628
629         if (priv->needs_scale) 
630                 {
631                         GdkPixbuf *tmp, *pixbuf;
632                         
633                         tmp = gdk_pixbuf_animation_get_static_image (priv->animation);
634                         g_object_ref (tmp);
635                         pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, tmp->has_alpha, 8, priv->width, priv->height);
636                         g_object_unref (priv->animation);
637                         priv->animation = gdk_pixbuf_non_anim_new (pixbuf);
638                         g_object_unref (pixbuf);
639                         g_signal_emit (loader, pixbuf_loader_signals[AREA_PREPARED], 0);
640                         gdk_pixbuf_scale (tmp, pixbuf, 0, 0, priv->width, priv->height, 0, 0,
641                                           (double) priv->width / tmp->width,
642                                           (double) priv->height / tmp->height,
643                                           GDK_INTERP_BILINEAR); 
644                         g_object_unref (tmp);
645                         
646                         g_signal_emit (loader, pixbuf_loader_signals[AREA_UPDATED], 0, 
647                                        0, 0, priv->width, priv->height);
648                 }
649
650         
651         g_signal_emit (loader, pixbuf_loader_signals[CLOSED], 0);
652
653         return retval;
654 }
655
656 /**
657  * gdk_pixbuf_loader_get_format:
658  * @loader: A pixbuf loader.
659  *
660  * Obtains the available information about the format of the 
661  * currently loading image file.
662  *
663  * Returns: A #GdkPixbufFormat or %NULL. The return value is owned 
664  * by GdkPixbuf and should not be freed.
665  */
666 GdkPixbufFormat *
667 gdk_pixbuf_loader_get_format (GdkPixbufLoader *loader)
668 {
669         GdkPixbufLoaderPrivate *priv;
670   
671         g_return_val_if_fail (loader != NULL, NULL);
672         g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
673   
674         priv = loader->priv;
675
676         if (priv->image_module)
677                 return _gdk_pixbuf_get_format (priv->image_module);
678         else
679                 return NULL;
680 }
681
682
683
684