aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-05-20 02:16:02 +0200
committerPřemysl Eric Janouch <p@janouch.name>2023-05-21 23:31:34 +0200
commit5af36f49540533359782b0ac202e4eb8ff14928d (patch)
treef75c6674d7264c2aaa772045e624b98ba3e54d75
parentac72a72afcbfed0ddb51172151148bbc42c415f9 (diff)
downloadfiv-5af36f49540533359782b0ac202e4eb8ff14928d.tar.gz
fiv-5af36f49540533359782b0ac202e4eb8ff14928d.tar.xz
fiv-5af36f49540533359782b0ac202e4eb8ff14928d.zip
Fix raw image thumbnailing speed regression
LibRaw started returning the largest possible thumbnail, which in the case of NEFs may be a nearly full-scale image.
-rw-r--r--fiv-thumbnail.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/fiv-thumbnail.c b/fiv-thumbnail.c
index dacbf22..c552073 100644
--- a/fiv-thumbnail.c
+++ b/fiv-thumbnail.c
@@ -290,12 +290,42 @@ fiv_thumbnail_extract(GFile *target, FivThumbnailSize max_size, GError **error)
int err = 0;
if ((err = libraw_open_buffer(iprc, (void *) g_mapped_file_get_contents(mf),
- g_mapped_file_get_length(mf))) ||
- (err = libraw_unpack_thumb(iprc))) {
+ g_mapped_file_get_length(mf)))) {
set_error(error, libraw_strerror(err));
goto fail_libraw;
}
+#if LIBRAW_VERSION >= LIBRAW_MAKE_VERSION(0, 21, 0)
+ if (!iprc->thumbs_list.thumbcount) {
+ set_error(error, "no thumbnails found");
+ goto fail_libraw;
+ }
+
+ // The old libraw_unpack_thumb() goes for the largest thumbnail,
+ // but we currently want the smallest thumbnail.
+ // TODO(p): To handle the ugly IFD0 thumbnail of NEF,
+ // try to go for the second smallest size. Remember to reflect tflip.
+ int best_index = 0;
+ float best_pixels = INFINITY;
+ for (int i = 0; i < iprc->thumbs_list.thumbcount; i++) {
+ float pixels = (float) iprc->thumbs_list.thumblist[i].twidth *
+ (float) iprc->thumbs_list.thumblist[i].theight;
+ if (pixels && pixels < best_pixels) {
+ best_index = i;
+ best_pixels = pixels;
+ }
+ }
+ if ((err = libraw_unpack_thumb_ex(iprc, best_index))) {
+ set_error(error, libraw_strerror(err));
+ goto fail_libraw;
+ }
+#else
+ if ((err = libraw_unpack_thumb(iprc))) {
+ set_error(error, libraw_strerror(err));
+ goto fail_libraw;
+ }
+#endif
+
libraw_processed_image_t *image = libraw_dcraw_make_mem_thumb(iprc, &err);
if (!image) {
set_error(error, libraw_strerror(err));