From f7ee7f3c8b5d4bd171150bf3a6d56cc97ea84344 Mon Sep 17 00:00:00 2001 From: Rodd Zurcher Date: Tue, 14 Jun 2011 05:56:32 +0200 Subject: [PATCH] Bug 663955 - Instead of decoding twice, use gdk_pixbuf_get_file_info to get the image width and height; then if either is larger than 180, call gdk_pixbuf_new_from_file_at_size, otherwise call gdk_pixbuf_new_from_file. r=roc --HG-- extra : transplant_source : n%B2%BC%C2Ov%21%EC%8B%ADF6%DC%DD%19v%B6%E1%97%B8 --- widget/src/gtk2/nsFilePicker.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/widget/src/gtk2/nsFilePicker.cpp b/widget/src/gtk2/nsFilePicker.cpp index 915d6a71c3ce..1964a79f9ff1 100644 --- a/widget/src/gtk2/nsFilePicker.cpp +++ b/widget/src/gtk2/nsFilePicker.cpp @@ -136,19 +136,30 @@ UpdateFilePreviewWidget(GtkFileChooser *file_chooser, return; } - // We do this so GTK scales down images that are too big, but not scale up images that are too small - GdkPixbuf *preview_pixbuf = gdk_pixbuf_new_from_file(image_filename, NULL); - if (!preview_pixbuf) { + gint preview_width = 0; + gint preview_height = 0; + GdkPixbufFormat *preview_format = gdk_pixbuf_get_file_info(image_filename, + &preview_width, + &preview_height); + if (!preview_format) { g_free(image_filename); gtk_file_chooser_set_preview_widget_active(file_chooser, FALSE); return; } - if (gdk_pixbuf_get_width(preview_pixbuf) > MAX_PREVIEW_SIZE || gdk_pixbuf_get_height(preview_pixbuf) > MAX_PREVIEW_SIZE) { - g_object_unref(preview_pixbuf); - preview_pixbuf = gdk_pixbuf_new_from_file_at_size(image_filename, MAX_PREVIEW_SIZE, MAX_PREVIEW_SIZE, NULL); + + GdkPixbuf *preview_pixbuf; + // Only scale down images that are too big + if (preview_width > MAX_PREVIEW_SIZE || preview_height > MAX_PREVIEW_SIZE) { + preview_pixbuf = gdk_pixbuf_new_from_file_at_size(image_filename, + MAX_PREVIEW_SIZE, + MAX_PREVIEW_SIZE, NULL); + } + else { + preview_pixbuf = gdk_pixbuf_new_from_file(image_filename, NULL); } g_free(image_filename); + if (!preview_pixbuf) { gtk_file_chooser_set_preview_widget_active(file_chooser, FALSE); return;