comparison src/gtkaccount.c @ 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 bec9130b24d2
children f175ff63d571
comparison
equal deleted inserted replaced
10522:e8b160971254 10523:f5c9438982f8
560 (width < prpl_info->icon_spec.min_width || 560 (width < prpl_info->icon_spec.min_width ||
561 width > prpl_info->icon_spec.max_width || 561 width > prpl_info->icon_spec.max_width ||
562 height < prpl_info->icon_spec.min_height || 562 height < prpl_info->icon_spec.min_height ||
563 height > prpl_info->icon_spec.max_height)) 563 height > prpl_info->icon_spec.max_height))
564 { 564 {
565 int new_width = gdk_pixbuf_get_width(pixbuf); 565 int new_width = width;
566 int new_height = gdk_pixbuf_get_height(pixbuf); 566 int new_height = height;
567 567
568 if(new_width > prpl_info->icon_spec.max_width) 568 if(new_width > prpl_info->icon_spec.max_width)
569 new_width = prpl_info->icon_spec.max_width; 569 new_width = prpl_info->icon_spec.max_width;
570 else if(new_width < prpl_info->icon_spec.min_width) 570 else if(new_width < prpl_info->icon_spec.min_width)
571 new_width = prpl_info->icon_spec.min_width; 571 new_width = prpl_info->icon_spec.min_width;
572 if(new_height > prpl_info->icon_spec.max_height) 572 if(new_height > prpl_info->icon_spec.max_height)
573 new_height = prpl_info->icon_spec.max_height; 573 new_height = prpl_info->icon_spec.max_height;
574 else if(new_height < prpl_info->icon_spec.min_height) 574 else if(new_height < prpl_info->icon_spec.min_height)
575 new_height = prpl_info->icon_spec.min_height; 575 new_height = prpl_info->icon_spec.min_height;
576
577 /* preserve aspect ratio */
578 if ((double)height * (double)new_width >
579 (double)width * (double)new_height) {
580 new_width = 0.5 + (double)width * (double)new_height / (double)height;
581 } else {
582 new_height = 0.5 + (double)height * (double)new_width / (double)width;
583 }
576 584
577 scale = gdk_pixbuf_scale_simple (pixbuf, new_width, new_height, 585 scale = gdk_pixbuf_scale_simple (pixbuf, new_width, new_height,
578 GDK_INTERP_HYPER); 586 GDK_INTERP_HYPER);
579 g_object_unref(G_OBJECT(pixbuf)); 587 g_object_unref(G_OBJECT(pixbuf));
580 pixbuf = scale; 588 pixbuf = scale;
604 gaim_debug_info("buddyicon", "Converting buddy icon to %s as %s\n", prpl_formats[i], filename); 612 gaim_debug_info("buddyicon", "Converting buddy icon to %s as %s\n", prpl_formats[i], filename);
605 /* The gdk-pixbuf documentation is wrong. gdk_pixbuf_save returns TRUE if it was successful, 613 /* The gdk-pixbuf documentation is wrong. gdk_pixbuf_save returns TRUE if it was successful,
606 * FALSE if an error was set. */ 614 * FALSE if an error was set. */
607 if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == TRUE) 615 if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == TRUE)
608 break; 616 break;
617 gaim_debug_warning("buddyicon", "Could not convert to %s: %s\n", prpl_formats[i], error->message);
618 g_error_free(error);
619 error = NULL;
609 } 620 }
610 g_strfreev(prpl_formats); 621 g_strfreev(prpl_formats);
611 if (!error) { 622 if (!error) {
612 g_free(random); 623 g_free(random);
613 g_object_unref(G_OBJECT(pixbuf)); 624 g_object_unref(G_OBJECT(pixbuf));