comparison src/gtkaccount.c @ 9318:01c50436203e

[gaim-migrate @ 10126] i think this is more intelligent scaling. it would certainly be hard for it to be less intelligent scaling committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 19 Jun 2004 17:34:29 +0000
parents 74728ac40475
children 120e0607e1cd
comparison
equal deleted inserted replaced
9317:8e1ddf5d81d0 9318:01c50436203e
449 int width, height; 449 int width, height;
450 char **pixbuf_formats; 450 char **pixbuf_formats;
451 GdkPixbufFormat *format; 451 GdkPixbufFormat *format;
452 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(account->protocol_id)); 452 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(account->protocol_id));
453 char **prpl_formats = g_strsplit (prpl_info->icon_spec.format,",",0); 453 char **prpl_formats = g_strsplit (prpl_info->icon_spec.format,",",0);
454 454
455 format = gdk_pixbuf_get_file_info (path, &width, &height); 455 format = gdk_pixbuf_get_file_info (path, &width, &height);
456 pixbuf_formats = gdk_pixbuf_format_get_extensions(format); 456 pixbuf_formats = gdk_pixbuf_format_get_extensions(format);
457 457
458 if (str_array_match(pixbuf_formats, prpl_formats) && /* This is an acceptable format AND */ 458 if (str_array_match(pixbuf_formats, prpl_formats) && /* This is an acceptable format AND */
459 ((prpl_info->icon_spec.width > 0 && prpl_info->icon_spec.height > 0) || /* The prpl doesn't care about size OR*/ 459 (!(prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_SEND) || /* The prpl doesn't scale before it sends OR */
460 (prpl_info->icon_spec.width == width && prpl_info->icon_spec.height == height))) { /* The icon is the correct size */ 460 (prpl_info->icon_spec.min_width <= width &&
461 prpl_info->icon_spec.max_width >= width &&
462 prpl_info->icon_spec.min_height <= height &&
463 prpl_info->icon_spec.max_height >= height))) { /* The icon is the correct size */
461 #endif 464 #endif
462 gaim_account_set_buddy_icon(account, path); 465 gaim_account_set_buddy_icon(account, path);
463 #if GTK_CHECK_VERSION(2,4,0) 466 #if GTK_CHECK_VERSION(2,4,0)
464 } else { 467 } else {
465 int i; 468 int i;
467 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &error); 470 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &error);
468 GdkPixbuf *scale; 471 GdkPixbuf *scale;
469 char *random = g_strdup_printf("%x", g_random_int()); 472 char *random = g_strdup_printf("%x", g_random_int());
470 const char *dirname = gaim_buddy_icons_get_cache_dir(); 473 const char *dirname = gaim_buddy_icons_get_cache_dir();
471 char *filename = g_build_filename(dirname, random, NULL); 474 char *filename = g_build_filename(dirname, random, NULL);
472 if (prpl_info->icon_spec.width > 0 && prpl_info->icon_spec.height > 0) { 475 if (!error && prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_SEND) {
473 scale = gdk_pixbuf_scale_simple (pixbuf, prpl_info->icon_spec.width, prpl_info->icon_spec.height, GDK_INTERP_HYPER); 476 int new_width = gdk_pixbuf_get_width(pixbuf);
477 int new_height = gdk_pixbuf_get_height(pixbuf);
478
479 if(new_width > prpl_info->icon_spec.max_width)
480 new_width = prpl_info->icon_spec.max_width;
481 else if(new_width < prpl_info->icon_spec.min_width)
482 new_width = prpl_info->icon_spec.min_width;
483 if(new_height > prpl_info->icon_spec.max_height)
484 new_height = prpl_info->icon_spec.max_height;
485 else if(new_height < prpl_info->icon_spec.min_height)
486 new_height = prpl_info->icon_spec.min_height;
487
488 scale = gdk_pixbuf_scale_simple (pixbuf, new_width, new_height,
489 GDK_INTERP_HYPER);
474 gdk_pixbuf_unref(pixbuf); 490 gdk_pixbuf_unref(pixbuf);
475 pixbuf = scale; 491 pixbuf = scale;
476 } 492 }
477 if (error) { 493 if (error) {
478 g_free(filename); 494 g_free(filename);