Code

Scale preview pixmap as needed and cache scaled version.
authorjoncruz <joncruz@users.sourceforge.net>
Wed, 18 Feb 2009 08:56:07 +0000 (08:56 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Wed, 18 Feb 2009 08:56:07 +0000 (08:56 +0000)
src/dialogs/eek-preview.cpp
src/dialogs/eek-preview.h

index e0d0fb4e2d98c145f44c51bd4c2d838bd0e9cb76..1c1adf54331641f66445df4954dea02b34ef061c 100644 (file)
@@ -73,6 +73,13 @@ void eek_preview_set_pixbuf( EekPreview* preview, GdkPixbuf* pixbuf )
     preview->_previewPixbuf = pixbuf;
 
     gtk_widget_queue_draw(GTK_WIDGET(preview));
+
+    if (preview->_scaled) {
+        g_object_unref(preview->_scaled);
+        preview->_scaled = 0;
+    }
+    preview->_scaledW = gdk_pixbuf_get_width(preview->_previewPixbuf);
+    preview->_scaledH = gdk_pixbuf_get_height(preview->_previewPixbuf);
 }
 
 
@@ -320,7 +327,17 @@ gboolean eek_preview_expose_event( GtkWidget* widget, GdkEventExpose* event )
             gint w = 0;
             gint h = 0;
             gdk_drawable_get_size(drawable, &w, &h);
-            gdk_draw_pixbuf( drawable, 0, preview->_previewPixbuf, 0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0 );
+            if ((w != preview->_scaledW) || (h != preview->_scaledH)) {
+                if (preview->_scaled) {
+                    g_object_unref(preview->_scaled);
+                }
+                preview->_scaled = gdk_pixbuf_scale_simple(preview->_previewPixbuf, w, h, GDK_INTERP_BILINEAR);
+                preview->_scaledW = w;
+                preview->_scaledH = h;
+            }
+
+            GdkPixbuf* pix = (preview->_scaled) ? preview->_scaled : preview->_previewPixbuf;
+            gdk_draw_pixbuf( drawable, 0, pix, 0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0 );
         }
 
 
@@ -647,6 +664,8 @@ static void eek_preview_init( EekPreview *preview )
     preview->_r = 0x80;
     preview->_g = 0x80;
     preview->_b = 0xcc;
+    preview->_scaledW = 0;
+    preview->_scaledH = 0;
 
     preview->_hot = FALSE;
     preview->_within = FALSE;
@@ -658,6 +677,7 @@ static void eek_preview_init( EekPreview *preview )
     preview->_ratio = 100;
 
     preview->_previewPixbuf = 0;
+    preview->_scaled = 0;
 
 /*
     GdkColor color = {0};
index e4d935ae92395266a16e06c4d051eee6fb1af78b..6eb5c8930cd8e4fe8906eec408ffe8815c1876b6 100644 (file)
@@ -97,6 +97,8 @@ struct _EekPreview
     int _r;
     int _g;
     int _b;
+    int _scaledW;
+    int _scaledH;
 
     gboolean _hot;
     gboolean _within;
@@ -108,6 +110,7 @@ struct _EekPreview
     guint _ratio;
     guint _linked;
     GdkPixbuf* _previewPixbuf;
+    GdkPixbuf* _scaled;
 };
 
 struct _EekPreviewClass