aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-06-07 18:10:33 +0200
committerPřemysl Eric Janouch <p@janouch.name>2023-06-08 18:59:21 +0200
commit07d4ea2dde4ff362549bf89ef3c40c561e17043e (patch)
treef201376abc8228bf4545b2770d2bd9410e49dc22
parenta5b5e32c3bebe1801a41bc2ceb74a14dde22157d (diff)
downloadfiv-07d4ea2dde4ff362549bf89ef3c40c561e17043e.tar.gz
fiv-07d4ea2dde4ff362549bf89ef3c40c561e17043e.tar.xz
fiv-07d4ea2dde4ff362549bf89ef3c40c561e17043e.zip
Optimize thumbnail extraction
Don't go over the same data twice.
-rw-r--r--fiv-thumbnail.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/fiv-thumbnail.c b/fiv-thumbnail.c
index 51e53b2..12be5aa 100644
--- a/fiv-thumbnail.c
+++ b/fiv-thumbnail.c
@@ -219,9 +219,11 @@ adjust_thumbnail(cairo_surface_t *thumbnail, double row_height)
}
static cairo_surface_t *
-orient_thumbnail(cairo_surface_t *surface, FivIoOrientation orientation)
+orient_thumbnail(cairo_surface_t *surface)
{
- if (!surface || orientation <= FivIoOrientation0)
+ int orientation = (intptr_t) cairo_surface_get_user_data(
+ surface, &fiv_io_key_orientation);
+ if (orientation <= FivIoOrientation0)
return surface;
double w = 0, h = 0;
@@ -408,16 +410,10 @@ fiv_thumbnail_extract(GFile *target, FivThumbnailSize max_size, GError **error)
#endif // ! HAVE_LIBRAW
g_mapped_file_unref(mf);
- // Hardcode Exif orientation before adjust_thumbnail() might do so,
- // before the early return below.
- if (surface) {
- int orientation = (intptr_t) cairo_surface_get_user_data(
- surface, &fiv_io_key_orientation);
- surface = orient_thumbnail(surface, orientation);
- }
- if (!surface || max_size < FIV_THUMBNAIL_SIZE_MIN ||
- max_size > FIV_THUMBNAIL_SIZE_MAX)
- return surface;
+ if (!surface)
+ return NULL;
+ if (max_size < FIV_THUMBNAIL_SIZE_MIN || max_size > FIV_THUMBNAIL_SIZE_MAX)
+ return orient_thumbnail(surface);
cairo_surface_t *result =
adjust_thumbnail(surface, fiv_thumbnail_sizes[max_size].size);