From 90df6aec51309372260b02b3a9bd518d35da4f40 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 6 Jan 2010 19:23:09 +0100 Subject: Implemented threaded preloading of images. The number of preloads is currently hardcoded in preload.c, an option to change this will be added shortly. --- wallpapers.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'wallpapers.c') diff --git a/wallpapers.c b/wallpapers.c index 56a72c6..fd893f3 100644 --- a/wallpapers.c +++ b/wallpapers.c @@ -118,3 +118,43 @@ void add_dir_recursive(const gchar *path, sqlite_uint64 parent, GtkStatusbar *st g_free(msg); gdk_threads_leave(); } + +GdkPixbuf *resize_pixbuf(GdkPixbuf *orig, gint win_width, gint win_height, gint *_width, gint *_height, gdouble *ratio) { + GdkPixbuf *pb; + gint img_width, img_height, width, height; + gdouble scalex, scaley, width_ratio, height_ratio; + + img_width = gdk_pixbuf_get_width(orig); + img_height = gdk_pixbuf_get_height(orig); + + /* do we need to resize? */ + if(img_width > win_width || img_height > win_height) { + /* resize by width */ + width_ratio = (gdouble)img_width / (gdouble)win_width; + height_ratio = (gdouble)img_height / (gdouble)win_height; + if(width_ratio > height_ratio) { + width = win_width; + height = (gint)(1.0 / width_ratio * img_height); + scalex = (gdouble)width / (gdouble)img_width; + scaley = (gdouble)height / (gdouble)img_height; + } else { /* resize by height */ + height = win_height; + width = (gint)(1.0 / height_ratio * img_width); + scalex = (gdouble)width / (gdouble)img_width; + scaley = (gdouble)height / (gdouble)img_height; + } + if(width == 0 || height == 0) return NULL; + pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); + gdk_pixbuf_scale(orig, pb, 0, 0, width, height, 0, 0, scalex, scaley, GDK_INTERP_BILINEAR); + } else { + width = img_width; + height = img_height; + pb = gdk_pixbuf_copy(orig); + } + + *ratio = (gdouble)width / (gdouble)img_width; + *_width = width; + *_height = height; + + return pb; +} -- cgit v1.2.3