Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/thumbs_blend.c
| Show All 35 Lines | |||||
| #include "DNA_ID.h" /* For preview images... */ | #include "DNA_ID.h" /* For preview images... */ | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "IMB_thumbs.h" | #include "IMB_thumbs.h" | ||||
| #include "MEM_guardedalloc.h" | #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, | static ImBuf *imb_thumb_load_from_blend_id(const char *blen_path, | ||||
| const char *blen_group, | const char *blen_group, | ||||
| const char *blen_id) | const char *blen_id) | ||||
| { | { | ||||
| ImBuf *ima = NULL; | ImBuf *ima = NULL; | ||||
| LinkNode *ln, *names, *lp, *previews = NULL; | |||||
| BlendFileReadReport bf_reports = {.reports = 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) { | if (libfiledata == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* NOTE: we should handle all previews for a same group at once, would avoid reopening | int idcode = BKE_idtype_idcode_from_name(blen_group); | ||||
| * `.blend` file for each and every ID. However, this adds some complexity, | PreviewImage *preview = BLO_blendhandle_get_preview(libfiledata, idcode, blen_id); | ||||
| * 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); | BLO_blendhandle_close(libfiledata); | ||||
| if (!previews || (nnames != nprevs)) { | if (preview) { | ||||
| if (previews != 0) { | ima = BKE_previewimg_to_imbuf(preview, ICON_SIZE_PREVIEW); | ||||
| /* No previews at all is not a bug! */ | BKE_previewimg_freefunc(preview); | ||||
| 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; | |||||
| } | } | ||||
| 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; | return ima; | ||||
| } | } | ||||
| static ImBuf *imb_thumb_load_from_blendfile(const char *blen_path) | static ImBuf *imb_thumb_load_from_blendfile(const char *blen_path) | ||||
| { | { | ||||
| BlendThumbnail *data = BLO_thumbnail_from_file(blen_path); | BlendThumbnail *data = BLO_thumbnail_from_file(blen_path); | ||||
| ImBuf *ima = BKE_main_thumbnail_to_imbuf(NULL, data); | ImBuf *ima = BKE_main_thumbnail_to_imbuf(NULL, data); | ||||
| Show All 15 Lines | |||||