From: joncruz Date: Wed, 18 Feb 2009 08:56:07 +0000 (+0000) Subject: Scale preview pixmap as needed and cache scaled version. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e2a4cc753c4dc768a6c1ec7312559bc9f9fc0e85;p=inkscape.git Scale preview pixmap as needed and cache scaled version. --- diff --git a/src/dialogs/eek-preview.cpp b/src/dialogs/eek-preview.cpp index e0d0fb4e2..1c1adf543 100644 --- a/src/dialogs/eek-preview.cpp +++ b/src/dialogs/eek-preview.cpp @@ -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}; diff --git a/src/dialogs/eek-preview.h b/src/dialogs/eek-preview.h index e4d935ae9..6eb5c8930 100644 --- a/src/dialogs/eek-preview.h +++ b/src/dialogs/eek-preview.h @@ -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