]> Pileus Git - ~andy/gtk/commitdiff
Implement scaling for animations
authorMatthias Clasen <matthiasc@src.gnome.org>
Thu, 8 Mar 2007 16:21:09 +0000 (16:21 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 8 Mar 2007 16:21:09 +0000 (16:21 +0000)
svn path=/trunk/; revision=17430

gdk-pixbuf/ChangeLog
gdk-pixbuf/Makefile.am
gdk-pixbuf/gdk-pixbuf-loader.c
gdk-pixbuf/gdk-pixbuf-scaled-anim.c [new file with mode: 0644]
gdk-pixbuf/gdk-pixbuf-scaled-anim.h [new file with mode: 0644]

index b2951caf11f38c80963ddb670607ff4203f1cb41..eb3cbaa70ec0a05dd06a39242456f106606976d9 100644 (file)
@@ -1,3 +1,13 @@
+2007-03-08  Matthias Clasen <mclasen@redhat.com>
+
+       * gdk-pixbuf-scaled-anim.[hc]: Implement an animation
+       wrapper for scaling animations.  
+
+       * gdk-pixbuf-loader.c: Use GdkPixbufScaledAnim to scale
+       animations.  (#335752, Mike Morrison)
+
+       * Makefile.am: Glue.
+
 2007-03-06  Tor Lillqvist  <tml@novell.com>
 
        * Makefile.am: Further fixes for building on Win32 outside
index d812790619b2a5c2747ded18259bd2f75e070a2e..683f3c9de2f0ee03916b16dfca396d125fcfea2d 100644 (file)
@@ -346,6 +346,7 @@ libgdk_pixbuf_2_0_la_SOURCES =   \
        gdk-pixbuf-loader.c      \
        gdk-pixbuf-scale.c       \
        gdk-pixbuf-simple-anim.c \
+       gdk-pixbuf-scaled-anim.c \
        gdk-pixbuf-util.c        \
        gdk-pixdata.c            \
        gdk-pixbuf-enum-types.c
@@ -380,6 +381,7 @@ libgdk_pixbufinclude_HEADERS =      \
 noinst_HEADERS =               \
        gdk-pixbuf-alias.h      \
        gdk-pixbuf-private.h    \
+       gdk-pixbuf-scaled-anim.h \
        xpm-color-table.h
 
 BUILT_SOURCES =                \
index 12f8986da48d46eaae0d7da6c9173de941302e71..d1721451c4d6667e6d343f4da261df75906267cb 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);
@@ -728,21 +737,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);
                 }
diff --git a/gdk-pixbuf/gdk-pixbuf-scaled-anim.c b/gdk-pixbuf/gdk-pixbuf-scaled-anim.c
new file mode 100644 (file)
index 0000000..5bfb163
--- /dev/null
@@ -0,0 +1,264 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/* GdkPixbuf library - Simple transformations of animations
+ *
+ * Copyright (C) Red Hat, Inc
+ *
+ * Authors: Matthias Clasen <mclasen@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <glib.h>
+
+#include "gdk-pixbuf.h"
+#include "gdk-pixbuf-io.h"
+#include "gdk-pixbuf-scaled-anim.h"
+#include "gdk-pixbuf-alias.h"
+
+
+struct _GdkPixbufScaledAnimClass
+{
+        GdkPixbufAnimationClass parent_class;
+};
+
+struct _GdkPixbufScaledAnim
+{
+       GdkPixbufAnimation parent_instance;
+
+       GdkPixbufAnimation *anim;
+       gdouble xscale;
+       gdouble yscale;
+       gdouble tscale;
+
+       GdkPixbuf *current;
+};
+
+struct _GdkPixbufScaledAnimIterClass
+{
+        GdkPixbufAnimationClass parent_class;
+};
+
+struct _GdkPixbufScaledAnimIter
+{
+       GdkPixbufAnimationIter parent_instance;
+
+       GdkPixbufScaledAnim *scaled;
+        GdkPixbufAnimationIter *iter;
+};
+
+typedef struct _GdkPixbufScaledAnimIter GdkPixbufScaledAnimIter;
+typedef struct _GdkPixbufScaledAnimIterClass GdkPixbufScaledAnimIterClass;
+
+GdkPixbufScaledAnim *
+_gdk_pixbuf_scaled_anim_new (GdkPixbufAnimation *anim,
+                             gdouble             xscale,
+                             gdouble             yscale,
+                             gdouble             tscale)
+{
+       GdkPixbufScaledAnim *scaled;
+
+       scaled = g_object_new (GDK_TYPE_PIXBUF_SCALED_ANIM, NULL);
+
+       scaled->anim = g_object_ref (anim);
+       scaled->xscale = xscale;
+       scaled->yscale = yscale;
+       scaled->tscale = tscale;
+
+       return scaled;
+}
+
+G_DEFINE_TYPE (GdkPixbufScaledAnim, gdk_pixbuf_scaled_anim, GDK_TYPE_PIXBUF_ANIMATION);
+
+static void
+gdk_pixbuf_scaled_anim_init (GdkPixbufScaledAnim *scaled)
+{
+       scaled->xscale = 1.0;
+       scaled->yscale = 1.0;
+       scaled->tscale = 1.0;
+}
+
+static void
+gdk_pixbuf_scaled_anim_finalize (GObject *object)
+{
+       GdkPixbufScaledAnim *scaled = (GdkPixbufScaledAnim *)object;
+
+       if (scaled->anim) {
+               g_object_unref (scaled->anim);
+               scaled->anim = NULL;
+       }
+
+       if (scaled->current) {
+               g_object_unref (scaled->current);
+               scaled->current = NULL;
+       }
+}
+
+static gboolean
+is_static_image (GdkPixbufAnimation *anim)
+{
+       GdkPixbufScaledAnim *scaled = (GdkPixbufScaledAnim *)anim;
+
+       return gdk_pixbuf_animation_is_static_image (scaled->anim);
+}      
+
+static GdkPixbuf *
+get_scaled_pixbuf (GdkPixbufScaledAnim *scaled, 
+                   GdkPixbuf           *pixbuf)
+{
+       if (scaled->current) 
+               g_object_unref (scaled->current);
+
+       scaled->current  = gdk_pixbuf_scale_simple (pixbuf, 
+                       (int) (gdk_pixbuf_get_width (pixbuf) * scaled->xscale),
+                       (int) (gdk_pixbuf_get_height (pixbuf) * scaled->yscale),
+                       GDK_INTERP_BILINEAR);
+
+       return scaled->current;
+}
+
+static GdkPixbuf *
+get_static_image (GdkPixbufAnimation *anim)
+{
+       GdkPixbufScaledAnim *scaled = (GdkPixbufScaledAnim *)anim;
+       GdkPixbuf *pixbuf;
+       
+       pixbuf = gdk_pixbuf_animation_get_static_image (scaled->anim);
+       return get_scaled_pixbuf (scaled, pixbuf);
+}
+
+static void
+get_size (GdkPixbufAnimation *anim,
+         int                *width,
+         int                *height)
+{
+       GdkPixbufScaledAnim *scaled = (GdkPixbufScaledAnim *)anim;
+
+        GDK_PIXBUF_ANIMATION_GET_CLASS (scaled->anim)->get_size (scaled->anim, width, height);
+       if (width) 
+               *width = (int)(*width * scaled->xscale);
+       if (height)
+               *height = (int)(*height * scaled->yscale);
+}
+
+static GdkPixbufAnimationIter *
+get_iter (GdkPixbufAnimation *anim,
+          const GTimeVal     *start_time)
+{
+       GdkPixbufScaledAnim *scaled = (GdkPixbufScaledAnim *)anim;
+       GdkPixbufScaledAnimIter *iter;
+
+       iter = g_object_new (GDK_TYPE_PIXBUF_SCALED_ANIM_ITER, NULL);
+
+       iter->scaled = g_object_ref (scaled);
+       iter->iter = gdk_pixbuf_animation_get_iter (scaled->anim, start_time);
+       
+       return (GdkPixbufAnimationIter*)iter;
+}
+
+static void
+gdk_pixbuf_scaled_anim_class_init (GdkPixbufScaledAnimClass *klass)
+{
+        GObjectClass *object_class;
+        GdkPixbufAnimationClass *anim_class;
+
+        object_class = G_OBJECT_CLASS (klass);
+        anim_class = GDK_PIXBUF_ANIMATION_CLASS (klass);
+        
+        object_class->finalize = gdk_pixbuf_scaled_anim_finalize;
+        
+        anim_class->is_static_image = is_static_image;
+        anim_class->get_static_image = get_static_image;
+        anim_class->get_size = get_size;
+        anim_class->get_iter = get_iter;
+}
+
+
+G_DEFINE_TYPE (GdkPixbufScaledAnimIter, gdk_pixbuf_scaled_anim_iter, GDK_TYPE_PIXBUF_ANIMATION_ITER);
+
+static void
+gdk_pixbuf_scaled_anim_iter_init (GdkPixbufScaledAnimIter *iter)
+{
+}
+
+static int
+get_delay_time (GdkPixbufAnimationIter *iter)
+{
+       GdkPixbufScaledAnimIter *scaled = (GdkPixbufScaledAnimIter *)iter;
+       int delay;
+
+       delay = gdk_pixbuf_animation_iter_get_delay_time (scaled->iter);
+       delay = (int)(delay * scaled->scaled->tscale);
+
+       return delay;
+}
+
+static GdkPixbuf *
+get_pixbuf (GdkPixbufAnimationIter *iter)
+{
+       GdkPixbufScaledAnimIter *scaled = (GdkPixbufScaledAnimIter *)iter;
+       GdkPixbuf *pixbuf;
+       gboolean force_update;
+
+       pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (scaled->iter);
+       return get_scaled_pixbuf (scaled->scaled, pixbuf);
+}
+
+static gboolean 
+on_currently_loading_frame (GdkPixbufAnimationIter *iter)
+{
+       GdkPixbufScaledAnimIter *scaled = (GdkPixbufScaledAnimIter *)iter;
+
+       return gdk_pixbuf_animation_iter_on_currently_loading_frame (scaled->iter);
+}
+
+static gboolean
+advance (GdkPixbufAnimationIter *iter,
+        const GTimeVal         *current_time)
+{
+       GdkPixbufScaledAnimIter *scaled = (GdkPixbufScaledAnimIter *)iter;
+
+       return gdk_pixbuf_animation_iter_advance (scaled->iter, current_time);
+}
+
+static void
+gdk_pixbuf_scaled_anim_iter_finalize (GObject *object)
+{
+        GdkPixbufScaledAnimIter *iter = (GdkPixbufScaledAnimIter *)object;
+        
+       g_object_unref (iter->iter);
+       g_object_unref (iter->scaled);
+}
+
+static void
+gdk_pixbuf_scaled_anim_iter_class_init (GdkPixbufScaledAnimIterClass *klass)
+{
+        GObjectClass *object_class;
+        GdkPixbufAnimationIterClass *anim_iter_class;
+
+        object_class = G_OBJECT_CLASS (klass);
+        anim_iter_class = GDK_PIXBUF_ANIMATION_ITER_CLASS (klass);
+        
+        object_class->finalize = gdk_pixbuf_scaled_anim_iter_finalize;
+        
+        anim_iter_class->get_delay_time = get_delay_time;
+        anim_iter_class->get_pixbuf = get_pixbuf;
+        anim_iter_class->on_currently_loading_frame = on_currently_loading_frame;
+        anim_iter_class->advance = advance;
+}
+
+#define __GDK_PIXBUF_SCALED_ANIM_C__
+#include "gdk-pixbuf-aliasdef.c"
diff --git a/gdk-pixbuf/gdk-pixbuf-scaled-anim.h b/gdk-pixbuf/gdk-pixbuf-scaled-anim.h
new file mode 100644 (file)
index 0000000..58c38c5
--- /dev/null
@@ -0,0 +1,47 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/* GdkPixbuf library - Simple transformations of animations
+ *
+ * Copyright (C) 2007 Red Hat, Inc
+ *
+ * Authors: Matthias Clasen <mclasen@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GDK_PIXBUF_SCALED_ANIM_H
+#define GDK_PIXBUF_SCALED_ANIM_H
+
+#include <gdk-pixbuf/gdk-pixbuf-animation.h>
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_PIXBUF_SCALED_ANIM              (gdk_pixbuf_scaled_anim_get_type ())
+#define GDK_TYPE_PIXBUF_SCALED_ANIM_ITER         (gdk_pixbuf_scaled_anim_iter_get_type ())
+
+typedef struct _GdkPixbufScaledAnim GdkPixbufScaledAnim;
+typedef struct _GdkPixbufScaledAnimClass GdkPixbufScaledAnimClass;
+
+GType gdk_pixbuf_scaled_anim_get_type (void) G_GNUC_CONST;
+GType gdk_pixbuf_scaled_anim_iter_get_type (void) G_GNUC_CONST;
+
+GdkPixbufScaledAnim *_gdk_pixbuf_scaled_anim_new (GdkPixbufAnimation *anim,
+                                                  gdouble             xscale, 
+                                                  gdouble             yscale,
+                                                  gdouble             tscale);
+
+G_END_DECLS
+
+#endif  /* GDK_PIXBUF_SCALED_ANIM_H */