Blender V5.0
thumbs_blend.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10#include <cstring>
11
12#include "BLO_readfile.hh"
13
14#include "BKE_idtype.hh"
15#include "BKE_main.hh"
16#include "BKE_preview_image.hh"
17
18#include "IMB_imbuf_types.hh"
19#include "IMB_thumbs.hh"
20
21#include "MEM_guardedalloc.h"
22
23/* NOTE: we should handle all previews for a same group at once, would avoid reopening
24 * `.blend` file for each and every ID. However, this adds some complexity,
25 * so keep it for later. */
26static ImBuf *imb_thumb_load_from_blend_id(const char *blen_path,
27 const char *blen_group,
28 const char *blen_id)
29{
30 ImBuf *ima = nullptr;
31 BlendFileReadReport bf_reports = {};
32 bf_reports.reports = nullptr;
33
34 BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports);
35 if (libfiledata == nullptr) {
36 return nullptr;
37 }
38
39 int idcode = BKE_idtype_idcode_from_name(blen_group);
40 PreviewImage *preview = BLO_blendhandle_get_preview_for_id(libfiledata, idcode, blen_id);
41 BLO_blendhandle_close(libfiledata);
42
43 if (preview) {
46 }
47 return ima;
48}
49
50static ImBuf *imb_thumb_load_from_blendfile(const char *blen_path)
51{
53 ImBuf *ima = BKE_main_thumbnail_to_imbuf(nullptr, data);
54
55 if (data) {
57 }
58 return ima;
59}
60
61ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id)
62{
63 if (blen_group && blen_id) {
64 return imb_thumb_load_from_blend_id(blen_path, blen_group, blen_id);
65 }
66 return imb_thumb_load_from_blendfile(blen_path);
67}
short BKE_idtype_idcode_from_name(const char *idtype_name)
Definition idtype.cc:185
ImBuf * BKE_main_thumbnail_to_imbuf(Main *bmain, BlendThumbnail *data)
Definition main.cc:861
ImBuf * BKE_previewimg_to_imbuf(const PreviewImage *prv, int size)
void BKE_previewimg_freefunc(void *link)
external readfile function prototypes.
BlendThumbnail * BLO_thumbnail_from_file(const char *filepath)
Definition readfile.cc:1456
PreviewImage * BLO_blendhandle_get_preview_for_id(BlendHandle *bh, int ofblocktype, const char *name)
BlendHandle * BLO_blendhandle_from_file(const char *filepath, BlendFileReadReport *reports)
void BLO_blendhandle_close(BlendHandle *bh) ATTR_NONNULL(1)
@ ICON_SIZE_PREVIEW
Read Guarded memory(de)allocation.
BMesh const char void * data
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
static ImBuf * imb_thumb_load_from_blendfile(const char *blen_path)
static ImBuf * imb_thumb_load_from_blend_id(const char *blen_path, const char *blen_group, const char *blen_id)
ImBuf * IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id)