[Xfce4-commits] <ristretto:master> Improve thumbnail rendering (can be done with less instructions... but at least it works now)

Stephan Arts stephan at xfce.org
Wed Aug 12 12:20:33 CEST 2009


Updating branch refs/heads/master
         to cb5053d9d63db53016fd7d0b7873c4231a8280b2 (commit)
       from fd7996a3822de483c74595c7c9aa48ace04dddad (commit)

commit cb5053d9d63db53016fd7d0b7873c4231a8280b2
Author: Stephan Arts <stephan at xfce.org>
Date:   Sat Jun 13 13:29:09 2009 +0200

    Improve thumbnail rendering (can be done with less instructions... but at least it works now)

 src/thumbnail.c |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/thumbnail.c b/src/thumbnail.c
index 910a72d..654bf91 100644
--- a/src/thumbnail.c
+++ b/src/thumbnail.c
@@ -186,28 +186,35 @@ rstto_thumbnail_expose(GtkWidget *widget, GdkEventExpose *event)
 
         if (thumb_pixbuf)
         {
-            guint height = gdk_pixbuf_get_height (thumb->priv->pixbuf) - 10;
-            guint width = gdk_pixbuf_get_width (thumb->priv->pixbuf) - 10;
+            gint height = gdk_pixbuf_get_height (thumb->priv->pixbuf) - 10;
+            gint width = gdk_pixbuf_get_width (thumb->priv->pixbuf) - 10;
+            gdouble scale = 1.0;
+            GdkPixbuf *dst_thumb_pixbuf = NULL;
 
             if (gdk_pixbuf_get_width (thumb_pixbuf) > gdk_pixbuf_get_height (thumb_pixbuf))
             {
-                height = (guint)((gdouble)width / (gdouble)gdk_pixbuf_get_width (thumb_pixbuf) * (gdouble)gdk_pixbuf_get_height (thumb_pixbuf));
+                height = (gint)(((gdouble)gdk_pixbuf_get_height (thumb_pixbuf) / (gdouble)gdk_pixbuf_get_width (thumb_pixbuf)) * width);
+                scale = ((gdouble)width / (gdouble)gdk_pixbuf_get_width (thumb_pixbuf));
             }
             else
             {
-                width = (guint)((gdouble)height / (gdouble)gdk_pixbuf_get_height (thumb_pixbuf) * (gdouble)gdk_pixbuf_get_width (thumb_pixbuf));
+                width = (gint)(((gdouble)gdk_pixbuf_get_width (thumb_pixbuf) / (gdouble)gdk_pixbuf_get_height (thumb_pixbuf)) * height);
+                scale = ((gdouble)height / (gdouble)gdk_pixbuf_get_height (thumb_pixbuf));
             }
 
             gdk_pixbuf_fill (thumb->priv->pixbuf, 0x00000000);
-            gdk_pixbuf_scale (thumb_pixbuf, thumb->priv->pixbuf,
-                              ((widget->allocation.width - width) / 2), ((widget->allocation.height - height) / 2), 
-                              width,
-                              height,
-                              0, 0,
-                              (gdouble)width / ((gdouble)gdk_pixbuf_get_width (thumb_pixbuf)),
-                              (gdouble)height / ((gdouble)gdk_pixbuf_get_height (thumb_pixbuf)),
-                              GDK_INTERP_BILINEAR);
 
+            dst_thumb_pixbuf = gdk_pixbuf_scale_simple (thumb_pixbuf, width, height, GDK_INTERP_BILINEAR);
+
+            gdk_pixbuf_copy_area (dst_thumb_pixbuf,
+                                  0, 0,
+                                  width, height,
+                                  thumb->priv->pixbuf,
+                                  (gint)((gdouble)(gdk_pixbuf_get_width (thumb->priv->pixbuf) - width))/2,
+                                  (gint)((gdouble)(gdk_pixbuf_get_height (thumb->priv->pixbuf) - height))/2
+                                  );
+
+            g_object_unref (dst_thumb_pixbuf);
             g_object_unref (thumb_pixbuf);
         }
 



More information about the Xfce4-commits mailing list