Commit 7aa66bb5 authored by Ernestas Kulik's avatar Ernestas Kulik 🦑

file: don’t thumbnail internally when scaling up

When requesting the thumbnail icon of a file, if the requested size is
more than 25% larger than what the gnome-desktop thumbnail factory gives
us, the code tries to thumbnail the file using GdkPixbuf to avoid
possible quality degradation.

After 860f748a, that code path should
never be executed (but is, because of a missing change to the logic) and
is safe to remove.
parent 767c1e21
......@@ -59,8 +59,6 @@ struct ThumbnailState
NautilusDirectory *directory;
GCancellable *cancellable;
NautilusFile *file;
gboolean trying_original;
gboolean tried_original;
};
struct MountState
......@@ -3799,14 +3797,12 @@ link_info_start (NautilusDirectory *directory,
static void
thumbnail_done (NautilusDirectory *directory,
NautilusFile *file,
GdkPixbuf *pixbuf,
gboolean tried_original)
GdkPixbuf *pixbuf)
{
const char *thumb_mtime_str;
time_t thumb_mtime = 0;
file->details->thumbnail_is_up_to_date = TRUE;
file->details->thumbnail_tried_original = tried_original;
if (file->details->thumbnail)
{
g_object_unref (file->details->thumbnail);
......@@ -3820,17 +3816,10 @@ thumbnail_done (NautilusDirectory *directory,
if (pixbuf)
{
if (tried_original)
thumb_mtime_str = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::MTime");
if (thumb_mtime_str)
{
thumb_mtime = file->details->mtime;
}
else
{
thumb_mtime_str = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::MTime");
if (thumb_mtime_str)
{
thumb_mtime = atol (thumb_mtime_str);
}
thumb_mtime = atol (thumb_mtime_str);
}
if (thumb_mtime == 0 ||
......@@ -3878,13 +3867,12 @@ thumbnail_stop (NautilusDirectory *directory)
static void
thumbnail_got_pixbuf (NautilusDirectory *directory,
NautilusFile *file,
GdkPixbuf *pixbuf,
gboolean tried_original)
GdkPixbuf *pixbuf)
{
nautilus_directory_ref (directory);
nautilus_file_ref (file);
thumbnail_done (directory, file, pixbuf, tried_original);
thumbnail_done (directory, file, pixbuf);
nautilus_file_changed (file);
nautilus_file_unref (file);
......@@ -3989,7 +3977,6 @@ thumbnail_read_callback (GObject *source_object,
gboolean result;
NautilusDirectory *directory;
GdkPixbuf *pixbuf;
GFile *location;
state = user_data;
......@@ -4014,26 +4001,12 @@ thumbnail_read_callback (GObject *source_object,
g_free (file_contents);
}
if (pixbuf == NULL && state->trying_original)
{
state->trying_original = FALSE;
state->directory->details->thumbnail_state = NULL;
async_job_end (state->directory, "thumbnail");
location = g_file_new_for_path (state->file->details->thumbnail_path);
g_file_load_contents_async (location,
state->cancellable,
thumbnail_read_callback,
state);
g_object_unref (location);
}
else
{
state->directory->details->thumbnail_state = NULL;
async_job_end (state->directory, "thumbnail");
thumbnail_got_pixbuf (state->directory, state->file, pixbuf, state->tried_original);
thumbnail_got_pixbuf (state->directory, state->file, pixbuf);
thumbnail_state_free (state);
}
thumbnail_state_free (state);
nautilus_directory_unref (directory);
}
......@@ -4070,16 +4043,7 @@ thumbnail_start (NautilusDirectory *directory,
state->file = file;
state->cancellable = g_cancellable_new ();
if (file->details->thumbnail_wants_original)
{
state->tried_original = TRUE;
state->trying_original = TRUE;
location = nautilus_file_get_location (file);
}
else
{
location = g_file_new_for_path (file->details->thumbnail_path);
}
location = g_file_new_for_path (file->details->thumbnail_path);
directory->details->thumbnail_state = state;
......
......@@ -168,8 +168,6 @@ struct NautilusFileDetails
eel_boolean_bit got_custom_activation_uri : 1;
eel_boolean_bit thumbnail_is_up_to_date : 1;
eel_boolean_bit thumbnail_wants_original : 1;
eel_boolean_bit thumbnail_tried_original : 1;
eel_boolean_bit thumbnailing_failed : 1;
eel_boolean_bit is_thumbnailing : 1;
......
......@@ -5427,19 +5427,6 @@ nautilus_file_get_thumbnail_icon (NautilusFile *file,
file->details->thumbnail_scale = thumb_scale;
}
/* Don't scale up if more than 25%, then read the original
* image instead. We don't want to compare to exactly 100%,
* since the zoom level 150% gives thumbnails at 144, which is
* ok to scale up from 128. */
if (modified_size > 128 * 1.25 * scale &&
!file->details->thumbnail_wants_original &&
nautilus_can_thumbnail_internally (file))
{
/* Invalidate if we resize upward */
file->details->thumbnail_wants_original = TRUE;
nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL);
}
DEBUG ("Returning thumbnailed image, at size %d %d",
(int) (w * thumb_scale), (int) (h * thumb_scale));
}
......
......@@ -324,18 +324,6 @@ pixbuf_can_load_type (const char *mime_type)
return FALSE;
}
gboolean
nautilus_can_thumbnail_internally (NautilusFile *file)
{
char *mime_type;
gboolean res;
mime_type = nautilus_file_get_mime_type (file);
res = pixbuf_can_load_type (mime_type);
g_free (mime_type);
return res;
}
gboolean
nautilus_thumbnail_is_mimetype_limited_by_size (const char *mime_type)
{
......
......@@ -28,7 +28,6 @@
/* Returns NULL if there's no thumbnail yet. */
void nautilus_create_thumbnail (NautilusFile *file);
gboolean nautilus_can_thumbnail (NautilusFile *file);
gboolean nautilus_can_thumbnail_internally (NautilusFile *file);
gboolean nautilus_thumbnail_is_mimetype_limited_by_size
(const char *mime_type);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment