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.
This commit is contained in:
Přemysl Eric Janouch 2023-05-20 02:16:02 +02:00
parent ac72a72afc
commit 5af36f4954
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 32 additions and 2 deletions

View File

@ -290,12 +290,42 @@ fiv_thumbnail_extract(GFile *target, FivThumbnailSize max_size, GError **error)
int err = 0; int err = 0;
if ((err = libraw_open_buffer(iprc, (void *) g_mapped_file_get_contents(mf), if ((err = libraw_open_buffer(iprc, (void *) g_mapped_file_get_contents(mf),
g_mapped_file_get_length(mf))) || g_mapped_file_get_length(mf)))) {
(err = libraw_unpack_thumb(iprc))) {
set_error(error, libraw_strerror(err)); set_error(error, libraw_strerror(err));
goto fail_libraw; 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); libraw_processed_image_t *image = libraw_dcraw_make_mem_thumb(iprc, &err);
if (!image) { if (!image) {
set_error(error, libraw_strerror(err)); set_error(error, libraw_strerror(err));