diff --git a/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c b/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c index f662c77..7a0a67e 100644 --- a/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c +++ b/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c @@ -669,6 +669,42 @@ tvtj_jpeg_load_thumbnail (const JOCTET *content, +static GdkPixbuf* +scale_pixbuf (GdkPixbuf *source, + gint dest_width, + gint dest_height) +{ + gdouble wratio; + gdouble hratio; + gint source_width; + gint source_height; + + /* determine source pixbuf dimensions */ + source_width = gdk_pixbuf_get_width (source); + source_height = gdk_pixbuf_get_height (source); + + /* don't do anything if there is no need to resize */ + if (source_width <= dest_width && source_height <= dest_height) + return g_object_ref (source); + + /* determine which axis needs to be scaled down more */ + wratio = (gdouble) source_width / (gdouble) dest_width; + hratio = (gdouble) source_height / (gdouble) dest_height; + + /* adjust the other axis */ + if (hratio > wratio) + dest_width = rint (source_width / hratio); + else + dest_height = rint (source_height / wratio); + + /* scale the pixbuf down to the desired size */ + return gdk_pixbuf_scale_simple (source, MAX (dest_width, 1), + MAX (dest_height, 1), + GDK_INTERP_BILINEAR); +} + + + static void jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, GCancellable *cancellable, @@ -680,6 +716,7 @@ jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, struct stat statb; const gchar *uri; GdkPixbuf *pixbuf = NULL; + GdkPixbuf *scaled; gboolean streaming_needed = TRUE; JOCTET *content; GError *error = NULL; @@ -792,6 +829,10 @@ jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, if (pixbuf != NULL) { + scaled = scale_pixbuf (pixbuf, width, height); + g_object_unref (pixbuf); + pixbuf = scaled; + data.data = gdk_pixbuf_get_pixels (pixbuf); data.has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); data.bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf);