]> Pileus Git - ~andy/gtk/blobdiff - gdk-pixbuf/gdk-pixbuf-loader.c
Updated Slovenian translation
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf-loader.c
index 86702c91eec5e4cb396e0114ecf93fd45b78a9b4..981874c08558d931c88859dbcd11e7f994e2ea4d 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "gdk-pixbuf-private.h"
 #include "gdk-pixbuf-animation.h"
+#include "gdk-pixbuf-scaled-anim.h"
 #include "gdk-pixbuf-io.h"
 #include "gdk-pixbuf-loader.h"
 #include "gdk-pixbuf-marshal.h"
@@ -277,7 +278,15 @@ gdk_pixbuf_loader_prepare (GdkPixbuf          *pixbuf,
         else
                 anim = gdk_pixbuf_non_anim_new (pixbuf);
   
-        priv->animation = anim;
+       if (priv->needs_scale) {
+               priv->animation  = _gdk_pixbuf_scaled_anim_new (anim,   
+                                         (double) priv->width / gdk_pixbuf_get_width (pixbuf),
+                                         (double) priv->height / gdk_pixbuf_get_height (pixbuf),
+                                         1.0);
+                       g_object_unref (anim);
+       }
+       else
+               priv->animation = anim;
   
         if (!priv->needs_scale)
                 g_signal_emit (loader, pixbuf_loader_signals[AREA_PREPARED], 0);
@@ -303,6 +312,27 @@ gdk_pixbuf_loader_update (GdkPixbuf *pixbuf,
                                MIN (height, gdk_pixbuf_animation_get_height (priv->animation)));
 }
 
+/* Defense against broken loaders; DO NOT take this as a GError example! */
+static void
+gdk_pixbuf_loader_ensure_error (GdkPixbufLoader *loader,
+                                GError         **error)
+{ 
+        GdkPixbufLoaderPrivate *priv = loader->priv;
+
+        if (error == NULL || *error != NULL)
+                return;
+
+        g_warning ("Bug! loader '%s' didn't set an error on failure",
+                   priv->image_module->module_name);
+        g_set_error (error,
+                     GDK_PIXBUF_ERROR,
+                     GDK_PIXBUF_ERROR_FAILED,
+                     _("Internal error: Image loader module '%s' failed to"
+                       " complete an operation, but didn't give a reason for"
+                       " the failure"),
+                     priv->image_module->module_name);
+}
+
 static gint
 gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
                                const char      *image_type,
@@ -358,23 +388,7 @@ gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
   
         if (priv->context == NULL)
                 {
-                        /* Defense against broken loaders; DO NOT take this as a GError
-                         * example
-                         */
-                        if (error && *error == NULL)
-                                {
-                                        g_warning ("Bug! loader '%s' didn't set an error on failure",
-                                                   priv->image_module->module_name);
-                                        g_set_error (error,
-                                                     GDK_PIXBUF_ERROR,
-                                                     GDK_PIXBUF_ERROR_FAILED,
-                                                     _("Internal error: Image loader module '%s'"
-                                                       " failed to begin loading an image, but didn't"
-                                                       " give a reason for the failure"),
-                                                     priv->image_module->module_name);
-
-                                }
-      
+                        gdk_pixbuf_loader_ensure_error (loader, error);
                         return 0;
                 }
   
@@ -450,7 +464,7 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader,
       
                         eaten = gdk_pixbuf_loader_eat_header_write (loader, buf, count, error);
                         if (eaten <= 0)
-                                return FALSE;
+                               goto fail; 
       
                         count -= eaten;
                         buf += eaten;
@@ -458,27 +472,18 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader,
   
         if (count > 0 && priv->image_module->load_increment)
                 {
-                        gboolean retval;
-                        retval = priv->image_module->load_increment (priv->context, buf, count,
-                                                                     error);
-                        if (!retval && error && *error == NULL)
-                                {
-                                        /* Fix up busted image loader */
-                                        g_warning ("Bug! loader '%s' didn't set an error on failure",
-                                                   priv->image_module->module_name);
-                                        g_set_error (error,
-                                                     GDK_PIXBUF_ERROR,
-                                                     GDK_PIXBUF_ERROR_FAILED,
-                                                     _("Internal error: Image loader module '%s'"
-                                                       " failed to begin loading an image, but didn't"
-                                                       " give a reason for the failure"),
-                                                     priv->image_module->module_name);
-                                }
-
-                        return retval;
+                        if (!priv->image_module->load_increment (priv->context, buf, count,
+                                                                 error))
+                               goto fail;
                 }
       
         return TRUE;
+
+ fail:
+        gdk_pixbuf_loader_ensure_error (loader, error);
+        gdk_pixbuf_loader_close (loader, NULL);
+
+        return FALSE;
 }
 
 /**
@@ -696,8 +701,8 @@ gdk_pixbuf_loader_close (GdkPixbufLoader *loader,
   
         priv = loader->priv;
   
-        /* we expect it's not closed */
-        g_return_val_if_fail (priv->closed == FALSE, TRUE);
+        if (priv->closed)
+                return TRUE;
   
         /* We have less the LOADER_HEADER_SIZE bytes in the image.  
          * Flush it, and keep going. 
@@ -715,8 +720,17 @@ gdk_pixbuf_loader_close (GdkPixbufLoader *loader,
 
         if (priv->image_module && priv->image_module->stop_load && priv->context) 
                 {
-                        if (!priv->image_module->stop_load (priv->context, error))
-                                retval = FALSE;
+                        GError *tmp = NULL;
+                        if (!priv->image_module->stop_load (priv->context, &tmp) || tmp)
+                                {
+                                       /* don't call gdk_pixbuf_loader_ensure_error()
+                                        * here, since we might not get an error in the
+                                        * gdk_pixbuf_get_file_info() case
+                                        */
+                                       if (tmp)
+                                               g_propagate_error (error, tmp);
+                                        retval = FALSE;
+                                }
                 }
   
         priv->closed = TRUE;
@@ -727,21 +741,8 @@ gdk_pixbuf_loader_close (GdkPixbufLoader *loader,
 
         if (priv->needs_scale) 
                 {
-                        GdkPixbuf *tmp, *pixbuf;
-                        
-                        tmp = gdk_pixbuf_animation_get_static_image (priv->animation);
-                        g_object_ref (tmp);
-                        pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, tmp->has_alpha, 8, priv->width, priv->height);
-                        g_object_unref (priv->animation);
-                        priv->animation = gdk_pixbuf_non_anim_new (pixbuf);
-                        g_object_unref (pixbuf);
+
                         g_signal_emit (loader, pixbuf_loader_signals[AREA_PREPARED], 0);
-                        gdk_pixbuf_scale (tmp, pixbuf, 0, 0, priv->width, priv->height, 0, 0,
-                                          (double) priv->width / tmp->width,
-                                          (double) priv->height / tmp->height,
-                                          GDK_INTERP_BILINEAR); 
-                        g_object_unref (tmp);
-                        
                         g_signal_emit (loader, pixbuf_loader_signals[AREA_UPDATED], 0, 
                                        0, 0, priv->width, priv->height);
                 }