Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2021-08-25 10:56:07 +0300
committerJeroen Bakker <jeroen@blender.org>2021-08-25 11:00:55 +0300
commite91fd3b816b6362b1f065f2a46bfcfd5cc545185 (patch)
treee203c944bce6d4ca5182a58a3801242347f65ab8 /source/blender/imbuf
parenta2597f8b833ccbccd509e90f4527b093a5580b9e (diff)
Cleanup: separate IMB_thumb_load_blend in multiple functions.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/intern/thumbs_blend.c99
1 files changed, 54 insertions, 45 deletions
diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c
index 759f96af7c8..878aa44f0d9 100644
--- a/source/blender/imbuf/intern/thumbs_blend.c
+++ b/source/blender/imbuf/intern/thumbs_blend.c
@@ -41,64 +41,73 @@
#include "MEM_guardedalloc.h"
-ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id)
+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;
+
+ if (libfiledata == NULL) {
+ return NULL;
+ }
- if (blen_group && blen_id) {
- 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;
-
- if (libfiledata == NULL) {
- return ima;
- }
-
- /* 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);
-
- 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 ima;
- }
+ /* 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);
- 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;
+ BLO_blendhandle_close(libfiledata);
- if (STREQ(blockname, blen_id)) {
- if (img) {
- ima = BKE_previewimg_to_imbuf(img, ICON_SIZE_PREVIEW);
- }
- break;
- }
+ 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;
}
- else {
- BlendThumbnail *data;
- data = BLO_thumbnail_from_file(blen_path);
- ima = BKE_main_thumbnail_to_imbuf(NULL, data);
+ 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 (data) {
- MEM_freeN(data);
+ 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;
}
+
+static ImBuf *imb_thumb_load_from_blendfile(const char *blen_path)
+{
+ BlendThumbnail *data = BLO_thumbnail_from_file(blen_path);
+ ImBuf *ima = BKE_main_thumbnail_to_imbuf(NULL, data);
+
+ if (data) {
+ MEM_freeN(data);
+ }
+ return ima;
+}
+
+ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id)
+{
+ if (blen_group && blen_id) {
+ return imb_thumb_load_from_blend_id(blen_path, blen_group, blen_id);
+ }
+ else {
+ return imb_thumb_load_from_blendfile(blen_path);
+ }
+}