changeset 10523:f5c9438982f8

[gaim-migrate @ 11840] This should preserve aspect ratios when scaling buddy icons. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Tue, 18 Jan 2005 02:16:48 +0000
parents e8b160971254
children 98daaf2f3209
files src/buddyicon.c src/gtkaccount.c
diffstat 2 files changed, 33 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/buddyicon.c	Tue Jan 18 02:11:51 2005 +0000
+++ b/src/buddyicon.c	Tue Jan 18 02:16:48 2005 +0000
@@ -454,18 +454,32 @@
 
 void gaim_buddy_icon_get_scale_size(GaimBuddyIconSpec *spec, int *width, int *height)
 {
-	/* this should eventually get smarter about preserving the aspect
-	 * ratio when scaling, but gimmie a break, I just woke up */
 	if(spec && spec->scale_rules & GAIM_ICON_SCALE_DISPLAY) {
+		int new_width, new_height;
+
+		new_width = *width;
+		new_height = *height;
+
 		if(*width < spec->min_width)
-			*width = spec->min_width;
+			new_width = spec->min_width;
 		else if(*width > spec->max_width)
-			*width = spec->max_width;
+			new_width = spec->max_width;
 
 		if(*height < spec->min_height)
-			*height = spec->min_height;
+			new_height = spec->min_height;
 		else if(*height  > spec->max_height)
-			*height = spec->max_height;
+			new_height = spec->max_height;
+
+		/* preserve aspect ratio */
+		if ((double)*height * (double)new_width >
+			(double)*width * (double)new_height) {
+				new_width = 0.5 + (double)*width * (double)new_height / (double)*height;
+		} else {
+				new_height = 0.5 + (double)*height * (double)new_width / (double)*width;
+		}
+
+		*width = new_width;
+		*height = new_height;
 	}
 }
 
--- a/src/gtkaccount.c	Tue Jan 18 02:11:51 2005 +0000
+++ b/src/gtkaccount.c	Tue Jan 18 02:16:48 2005 +0000
@@ -562,8 +562,8 @@
 			 height < prpl_info->icon_spec.min_height ||
 			 height > prpl_info->icon_spec.max_height))
 		{
-			int new_width = gdk_pixbuf_get_width(pixbuf);
-			int new_height = gdk_pixbuf_get_height(pixbuf);
+			int new_width = width;
+			int new_height = height;
 
 			if(new_width > prpl_info->icon_spec.max_width)
 				new_width = prpl_info->icon_spec.max_width;
@@ -574,6 +574,14 @@
 			else if(new_height < prpl_info->icon_spec.min_height)
 				new_height = prpl_info->icon_spec.min_height;
 
+			/* preserve aspect ratio */
+			if ((double)height * (double)new_width >
+				(double)width * (double)new_height) {
+					new_width = 0.5 + (double)width * (double)new_height / (double)height;
+			} else {
+					new_height = 0.5 + (double)height * (double)new_width / (double)width;
+			}
+
 			scale = gdk_pixbuf_scale_simple (pixbuf, new_width, new_height,
 					GDK_INTERP_HYPER);
 			g_object_unref(G_OBJECT(pixbuf));
@@ -606,6 +614,9 @@
 			 * FALSE if an error was set. */
 			if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == TRUE)
 					break;
+			gaim_debug_warning("buddyicon", "Could not convert to %s: %s\n", prpl_formats[i], error->message);
+			g_error_free(error);
+			error = NULL;
 		}
 		g_strfreev(prpl_formats);
 		if (!error) {