diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-08-25 15:15:57 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-08-25 16:59:41 +0300 |
commit | 0fd1e6a5f43df8b0f5382c07975c0d031bbbb506 (patch) | |
tree | 07a7fa7e63b6a741e477b1deec9aa65f0820697d /source/blender/imbuf | |
parent | 5a0ec2302eeb33a03b36f8021bb2338e0dba2ee4 (diff) |
T90908: Reduce loading times when extracting thumbnails from Blendfiles.
Previously when loading an thumbnails for an asset the whole file was
read. Reason this was done was perhaps a future idea to load
all thumbnails inside a blendfile in a single go. This was never implemented
and currently unneeded disk and cpu cycles was spend with finding out what
preview to load.
This patch adds an early break when the thumbnail that the caller is
interested in has been found. This improves the thumbnail extraction
when looking into large files.
Reviewed By: mont29
Maniphest Tasks: T90908
Differential Revision: https://developer.blender.org/D12312
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/intern/thumbs_blend.c | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index 878aa44f0d9..085620cb785 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -41,53 +41,29 @@ #include "MEM_guardedalloc.h" +/* NOTE: we should handle all previews for a same group at once, would avoid reopening + * `.blend` file for each and every ID. However, this adds some complexity, + * so keep it for later. */ static ImBuf *imb_thumb_load_from_blend_id(const char *blen_path, const char *blen_group, const char *blen_id) { ImBuf *ima = NULL; - LinkNode *ln, *names, *lp, *previews = NULL; BlendFileReadReport bf_reports = {.reports = NULL}; - struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports); - int idcode = BKE_idtype_idcode_from_name(blen_group); - int i, nprevs, nnames; + struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports); if (libfiledata == NULL) { return NULL; } - /* NOTE: we should handle all previews for a same group at once, would avoid reopening - * `.blend` file for each and every ID. However, this adds some complexity, - * so keep it for later. */ - names = BLO_blendhandle_get_datablock_names(libfiledata, idcode, false, &nnames); - previews = BLO_blendhandle_get_previews(libfiledata, idcode, &nprevs); - + int idcode = BKE_idtype_idcode_from_name(blen_group); + PreviewImage *preview = BLO_blendhandle_get_preview_for_id(libfiledata, idcode, blen_id); BLO_blendhandle_close(libfiledata); - if (!previews || (nnames != nprevs)) { - if (previews != 0) { - /* No previews at all is not a bug! */ - printf("%s: error, found %d items, %d previews\n", __func__, nnames, nprevs); - } - BLI_linklist_free(previews, BKE_previewimg_freefunc); - BLI_linklist_freeN(names); - return NULL; + if (preview) { + ima = BKE_previewimg_to_imbuf(preview, ICON_SIZE_PREVIEW); + BKE_previewimg_freefunc(preview); } - - for (i = 0, ln = names, lp = previews; i < nnames; i++, ln = ln->next, lp = lp->next) { - const char *blockname = ln->link; - PreviewImage *img = lp->link; - - if (STREQ(blockname, blen_id)) { - if (img) { - ima = BKE_previewimg_to_imbuf(img, ICON_SIZE_PREVIEW); - } - break; - } - } - - BLI_linklist_free(previews, BKE_previewimg_freefunc); - BLI_linklist_freeN(names); return ima; } |