From 788485d81eefcd43f0a66cf4cc664f8bde4423f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Mon, 24 Jan 2022 04:03:19 +0100 Subject: Redirect warnings to the info bar And speed up thumbnailing of animated images while at it. Also, fix thumbnailing SVGs with external links. --- fiv-thumbnail.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'fiv-thumbnail.c') diff --git a/fiv-thumbnail.c b/fiv-thumbnail.c index c6a616b..ef84079 100644 --- a/fiv-thumbnail.c +++ b/fiv-thumbnail.c @@ -252,15 +252,24 @@ fiv_thumbnail_produce(GFile *target, FivThumbnailSize max_size, GError **error) return FALSE; } - // TODO(p): Add a flag to avoid loading all pages and frames. - FivIoProfile sRGB = fiv_io_profile_new_sRGB(); + FivIoOpenContext ctx = { + .uri = g_file_get_uri(target), + .screen_profile = fiv_io_profile_new_sRGB(), + .screen_dpi = 96, + .first_frame_only = TRUE, + // Only using this array as a redirect. + .warnings = g_ptr_array_new_with_free_func(g_free), + }; + gsize filesize = g_mapped_file_get_length(mf); cairo_surface_t *surface = fiv_io_open_from_data( - g_mapped_file_get_contents(mf), filesize, path, sRGB, FALSE, error); - + g_mapped_file_get_contents(mf), filesize, &ctx, error); g_mapped_file_unref(mf); - if (sRGB) - fiv_io_profile_free(sRGB); + + g_free((gchar *) ctx.uri); + g_ptr_array_free(ctx.warnings, TRUE); + if (ctx.screen_profile) + fiv_io_profile_free(ctx.screen_profile); if (!surface) return FALSE; @@ -285,7 +294,7 @@ fiv_thumbnail_produce(GFile *target, FivThumbnailSize max_size, GError **error) } // Without a CMM, no conversion is attempted. - if (sRGB) { + if (ctx.screen_profile) { g_string_append_printf( thum, "%s%c%s%c", THUMB_COLORSPACE, 0, THUMB_COLORSPACE_SRGB, 0); } @@ -347,7 +356,8 @@ read_wide_thumbnail( if (!thumbnail_uri) return NULL; - cairo_surface_t *surface = fiv_io_open(thumbnail_uri, NULL, FALSE, error); + cairo_surface_t *surface = + fiv_io_open(&(FivIoOpenContext){.uri = thumbnail_uri}, error); g_free(thumbnail_uri); if (!surface) return NULL; -- cgit v1.2.3