Blender
V4.3
source
blender
imbuf
intern
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
9
#include <cstdio>
10
#include <cstdlib>
11
#include <cstring>
12
13
#include "
BLI_listbase.h
"
/* Needed due to import of BLO_readfile.hh */
14
#include "
BLI_utildefines.h
"
15
16
#include "
BLO_readfile.hh
"
17
18
#include "
BKE_idtype.hh
"
19
#include "
BKE_main.hh
"
20
#include "
BKE_preview_image.hh
"
21
22
#include "
IMB_imbuf_types.hh
"
23
#include "
IMB_thumbs.hh
"
24
25
#include "
MEM_guardedalloc.h
"
26
27
/* NOTE: we should handle all previews for a same group at once, would avoid reopening
28
* `.blend` file for each and every ID. However, this adds some complexity,
29
* so keep it for later. */
30
static
ImBuf
*
imb_thumb_load_from_blend_id
(
const
char
*blen_path,
31
const
char
*blen_group,
32
const
char
*blen_id)
33
{
34
ImBuf
*ima =
nullptr
;
35
BlendFileReadReport
bf_reports = {};
36
bf_reports.
reports
=
nullptr
;
37
38
BlendHandle *libfiledata =
BLO_blendhandle_from_file
(blen_path, &bf_reports);
39
if
(libfiledata ==
nullptr
) {
40
return
nullptr
;
41
}
42
43
int
idcode =
BKE_idtype_idcode_from_name
(blen_group);
44
PreviewImage
*preview =
BLO_blendhandle_get_preview_for_id
(libfiledata, idcode, blen_id);
45
BLO_blendhandle_close
(libfiledata);
46
47
if
(preview) {
48
ima =
BKE_previewimg_to_imbuf
(preview,
ICON_SIZE_PREVIEW
);
49
BKE_previewimg_freefunc
(preview);
50
}
51
return
ima;
52
}
53
54
static
ImBuf
*
imb_thumb_load_from_blendfile
(
const
char
*blen_path)
55
{
56
BlendThumbnail
*data =
BLO_thumbnail_from_file
(blen_path);
57
ImBuf
*ima =
BKE_main_thumbnail_to_imbuf
(
nullptr
, data);
58
59
if
(data) {
60
MEM_freeN
(data);
61
}
62
return
ima;
63
}
64
65
ImBuf
*
IMB_thumb_load_blend
(
const
char
*blen_path,
const
char
*blen_group,
const
char
*blen_id)
66
{
67
if
(blen_group && blen_id) {
68
return
imb_thumb_load_from_blend_id
(blen_path, blen_group, blen_id);
69
}
70
return
imb_thumb_load_from_blendfile
(blen_path);
71
}
BKE_idtype.hh
BKE_idtype_idcode_from_name
short BKE_idtype_idcode_from_name(const char *idtype_name)
Definition
idtype.cc:189
BKE_main.hh
BKE_main_thumbnail_to_imbuf
ImBuf * BKE_main_thumbnail_to_imbuf(Main *bmain, BlendThumbnail *data)
Definition
main.cc:806
BKE_preview_image.hh
BKE_previewimg_freefunc
void BKE_previewimg_freefunc(void *link)
Definition
preview_image.cc:122
BKE_previewimg_to_imbuf
ImBuf * BKE_previewimg_to_imbuf(PreviewImage *prv, int size)
Definition
preview_image.cc:437
BLI_listbase.h
BLI_utildefines.h
BLO_readfile.hh
external readfile function prototypes.
BLO_thumbnail_from_file
BlendThumbnail * BLO_thumbnail_from_file(const char *filepath)
Definition
readfile.cc:1422
BLO_blendhandle_get_preview_for_id
PreviewImage * BLO_blendhandle_get_preview_for_id(BlendHandle *bh, int ofblocktype, const char *name)
Definition
readblenentry.cc:218
BLO_blendhandle_from_file
BlendHandle * BLO_blendhandle_from_file(const char *filepath, BlendFileReadReport *reports)
Definition
readblenentry.cc:62
BLO_blendhandle_close
void BLO_blendhandle_close(BlendHandle *bh) ATTR_NONNULL(1)
Definition
readblenentry.cc:286
ICON_SIZE_PREVIEW
@ ICON_SIZE_PREVIEW
Definition
DNA_ID_enums.h:18
IMB_imbuf_types.hh
Contains defines and structs used throughout the imbuf module.
IMB_thumbs.hh
MEM_guardedalloc.h
Read Guarded memory(de)allocation.
MEM_freeN
void MEM_freeN(void *vmemh)
Definition
mallocn.cc:105
BlendFileReadReport
Definition
BLO_readfile.hh:99
BlendFileReadReport::reports
ReportList * reports
Definition
BLO_readfile.hh:101
BlendThumbnail
Definition
BKE_main.hh:43
ImBuf
Definition
IMB_imbuf_types.hh:185
PreviewImage
Definition
DNA_ID.h:600
imb_thumb_load_from_blendfile
static ImBuf * imb_thumb_load_from_blendfile(const char *blen_path)
Definition
thumbs_blend.cc:54
imb_thumb_load_from_blend_id
static ImBuf * imb_thumb_load_from_blend_id(const char *blen_path, const char *blen_group, const char *blen_id)
Definition
thumbs_blend.cc:30
IMB_thumb_load_blend
ImBuf * IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id)
Definition
thumbs_blend.cc:65
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0