From f4afe8428691a13bd2d3de58a363317dc8f4a132 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Sat, 28 Feb 2004 01:22:47 +0000 Subject: ref the pixbuf before we close/unref the loader so the pixbuf sticks 2004-02-27 Chris Toshok * gui/widgets/eab-contact-display.c (eab_contact_display_render_compact): ref the pixbuf before we close/unref the loader so the pixbuf sticks around, and make the scaling logic a bit more transparent. svn path=/trunk/; revision=24916 --- addressbook/gui/widgets/eab-contact-display.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'addressbook/gui') diff --git a/addressbook/gui/widgets/eab-contact-display.c b/addressbook/gui/widgets/eab-contact-display.c index c1ceb7c335..87c8502147 100644 --- a/addressbook/gui/widgets/eab-contact-display.c +++ b/addressbook/gui/widgets/eab-contact-display.c @@ -370,18 +370,24 @@ eab_contact_display_render_compact (EABContactDisplay *display, EContact *contac the html */ gdk_pixbuf_loader_write (loader, photo->data, photo->length, NULL); pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); + if (pixbuf) + gdk_pixbuf_ref (pixbuf); gdk_pixbuf_loader_close (loader, NULL); g_object_unref (loader); if (pixbuf) { - int max_dimension = gdk_pixbuf_get_height (pixbuf); - if (max_dimension < gdk_pixbuf_get_width (pixbuf)) - max_dimension = gdk_pixbuf_get_width (pixbuf); + int max_dimension; - calced_width = (float)gdk_pixbuf_get_width (pixbuf) / max_dimension * MAX_COMPACT_IMAGE_DIMENSION; - calced_height = (float)gdk_pixbuf_get_height (pixbuf) / max_dimension * MAX_COMPACT_IMAGE_DIMENSION; + calced_width = gdk_pixbuf_get_width (pixbuf); + calced_height = gdk_pixbuf_get_height (pixbuf); - calced_width = MIN (calced_width, MAX_COMPACT_IMAGE_DIMENSION); - calced_height = MIN (calced_height, MAX_COMPACT_IMAGE_DIMENSION); + max_dimension = calced_width; + if (max_dimension < calced_height) + max_dimension = calced_height; + + if (max_dimension > MAX_COMPACT_IMAGE_DIMENSION) { + calced_width *= ((float)MAX_COMPACT_IMAGE_DIMENSION / max_dimension); + calced_height *= ((float)MAX_COMPACT_IMAGE_DIMENSION / max_dimension); + } } gdk_pixbuf_unref (pixbuf); -- cgit