From af2eb411d92028b50f5b54b4b69bbc73cc0cae34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Mon, 27 Dec 2021 23:51:38 +0100 Subject: Try to regenerate low quality thumbnails --- fiv-io.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'fiv-io.c') diff --git a/fiv-io.c b/fiv-io.c index 97d10ed..eb2ea81 100644 --- a/fiv-io.c +++ b/fiv-io.c @@ -2288,6 +2288,8 @@ cairo_user_data_key_t fiv_io_key_loops; cairo_user_data_key_t fiv_io_key_page_next; cairo_user_data_key_t fiv_io_key_page_previous; +cairo_user_data_key_t fiv_io_key_thumbnail_lq; + cairo_surface_t * fiv_io_open( const gchar *path, FivIoProfile profile, gboolean enhance, GError **error) @@ -2764,6 +2766,13 @@ FivIoThumbnailSizeInfo // TODO(p): Put the constant in a header file, share with fiv-browser.c. static const double g_wide_thumbnail_factor = 2; +static void +mark_thumbnail_lq(cairo_surface_t *surface) +{ + cairo_surface_set_user_data( + surface, &fiv_io_key_thumbnail_lq, (void *) (intptr_t) 1, NULL); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // In principle similar to rescale_thumbnail() from fiv-browser.c. @@ -2804,6 +2813,7 @@ rescale_thumbnail(cairo_surface_t *thumbnail, double row_height) cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_destroy(cr); + mark_thumbnail_lq(scaled); return scaled; } @@ -2849,6 +2859,8 @@ fiv_io_produce_thumbnail(GFile *target, FivIoThumbnailSize size, GError **error) gchar *sum = g_compute_checksum_for_string(G_CHECKSUM_MD5, uri, -1); gchar *cache_dir = get_xdg_home_dir("XDG_CACHE_HOME", ".cache"); + // TODO(p): Never produce thumbnails for thumbnail directories. + for (int use = size; use >= FIV_IO_THUMBNAIL_SIZE_MIN; use--) { cairo_surface_t *scaled = rescale_thumbnail(surface, fiv_io_thumbnail_sizes[use].size); @@ -3058,7 +3070,7 @@ fiv_io_lookup_thumbnail(GFile *target, FivIoThumbnailSize size) cairo_surface_t *result = NULL; GError *error = NULL; for (int i = 0; i < FIV_IO_THUMBNAIL_SIZE_COUNT; i++) { - int use = size + i; + FivIoThumbnailSize use = size + i; if (use > FIV_IO_THUMBNAIL_SIZE_MAX) use = FIV_IO_THUMBNAIL_SIZE_MAX - i; @@ -3071,8 +3083,13 @@ fiv_io_lookup_thumbnail(GFile *target, FivIoThumbnailSize size) g_clear_error(&error); } g_free(wide); - if (result) + if (result) { + // Higher up we can't distinguish images smaller than the thumbnail. + // Also, try not to rescale the already rescaled. + if (use != size) + mark_thumbnail_lq(result); break; + } gchar *path = g_strdup_printf("%s/thumbnails/%s/%s.png", cache_dir, name, sum); @@ -3082,8 +3099,11 @@ fiv_io_lookup_thumbnail(GFile *target, FivIoThumbnailSize size) g_clear_error(&error); } g_free(path); - if (result) + if (result) { + // Whatever produced it, we may be able to outclass it. + mark_thumbnail_lq(result); break; + } } // TODO(p): We can definitely extract embedded thumbnails, but it should be -- cgit v1.2.3