mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-05 05:30:29 +00:00
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
This commit is contained in:
parent
6cd7bd535a
commit
d44ef4dca7
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user