Scale incoming thumbnails in the request dialog if they are overly large

Mon, 03 May 2010 20:23:17 +0000

author
Marcus Lundblad <malu@pidgin.im>
date
Mon, 03 May 2010 20:23:17 +0000
changeset 30166
2e26380774ef
parent 30165
1002ebf2d580
child 30167
bdf1bd968a91
child 30168
ff3cae005cb5
child 30171
cbff10cc0c16

Scale incoming thumbnails in the request dialog if they are overly large
WLM seems to send animations in some situations as a series of frames "encoded" in
a wide PNG...

libpurple/ft.c file | annotate | diff | comparison | revisions
pidgin/gtkrequest.c file | annotate | diff | comparison | revisions
--- a/libpurple/ft.c	Mon May 03 05:02:30 2010 +0000
+++ b/libpurple/ft.c	Mon May 03 20:23:17 2010 +0000
@@ -521,7 +521,7 @@
 		if ((thumb = purple_xfer_get_thumbnail(xfer, &thumb_size))) {
 			purple_request_accept_cancel_with_icon(xfer, NULL, buf, NULL,
 				PURPLE_DEFAULT_ACTION_NONE, xfer->account, xfer->who, NULL,
-				thumb, thumb_size, xfer, 
+				thumb, thumb_size, xfer,
 				G_CALLBACK(purple_xfer_choose_file),
 				G_CALLBACK(cancel_recv_cb));
 		} else {
--- a/pidgin/gtkrequest.c	Mon May 03 05:02:30 2010 +0000
+++ b/pidgin/gtkrequest.c	Mon May 03 20:23:17 2010 +0000
@@ -668,6 +668,23 @@
 		if (gdk_pixbuf_loader_write(loader, icon_data, icon_size, NULL)) {
 			pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
 			if (pixbuf) {
+				/* scale the image if it is too large */
+				int width = gdk_pixbuf_get_width(pixbuf);
+				int height = gdk_pixbuf_get_height(pixbuf);
+				if (width > 128 || height > 128) {
+					int scaled_width = width > height ? 128 : (128 * width) / height;
+					int scaled_height = height > width ? 128 : (128 * height) / width;
+					GdkPixbuf *scaled =
+							gdk_pixbuf_scale_simple(pixbuf, scaled_width, scaled_height,
+							    GDK_INTERP_BILINEAR);
+
+					purple_debug_info("pidgin",
+					    "dialog icon was too large, scale it down\n");
+					if (scaled) {
+						g_object_unref(pixbuf);
+						pixbuf = scaled;
+					}
+				}
 				img = gtk_image_new_from_pixbuf(pixbuf);
 			}
 		} else {

mercurial