Blender  V3.3
thumbs_blend.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include "BLI_linklist.h"
12 #include "BLI_listbase.h" /* Needed due to import of BLO_readfile.h */
13 #include "BLI_utildefines.h"
14 
15 #include "BLO_blend_defs.h"
16 #include "BLO_readfile.h"
17 
18 #include "BKE_icons.h"
19 #include "BKE_idtype.h"
20 #include "BKE_main.h"
21 
22 #include "DNA_ID.h" /* For preview images... */
23 
24 #include "IMB_imbuf.h"
25 #include "IMB_imbuf_types.h"
26 #include "IMB_thumbs.h"
27 
28 #include "MEM_guardedalloc.h"
29 
30 /* NOTE: we should handle all previews for a same group at once, would avoid reopening
31  * `.blend` file for each and every ID. However, this adds some complexity,
32  * so keep it for later. */
33 static ImBuf *imb_thumb_load_from_blend_id(const char *blen_path,
34  const char *blen_group,
35  const char *blen_id)
36 {
37  ImBuf *ima = NULL;
38  BlendFileReadReport bf_reports = {.reports = NULL};
39 
40  struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports);
41  if (libfiledata == NULL) {
42  return NULL;
43  }
44 
45  int idcode = BKE_idtype_idcode_from_name(blen_group);
46  PreviewImage *preview = BLO_blendhandle_get_preview_for_id(libfiledata, idcode, blen_id);
47  BLO_blendhandle_close(libfiledata);
48 
49  if (preview) {
52  }
53  return ima;
54 }
55 
56 static ImBuf *imb_thumb_load_from_blendfile(const char *blen_path)
57 {
60 
61  if (data) {
62  MEM_freeN(data);
63  }
64  return ima;
65 }
66 
67 ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id)
68 {
69  if (blen_group && blen_id) {
70  return imb_thumb_load_from_blend_id(blen_path, blen_group, blen_id);
71  }
72  return imb_thumb_load_from_blendfile(blen_path);
73 }
void BKE_previewimg_freefunc(void *link)
Definition: icons.cc:266
struct ImBuf * BKE_previewimg_to_imbuf(struct PreviewImage *prv, int size)
Definition: icons.cc:567
short BKE_idtype_idcode_from_name(const char *idtype_name)
Definition: idtype.c:163
struct ImBuf * BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlendThumbnail *data)
Definition: main.c:532
defines for blend-file codes.
external readfile function prototypes.
struct PreviewImage * BLO_blendhandle_get_preview_for_id(BlendHandle *bh, int ofblocktype, const char *name)
BlendHandle * BLO_blendhandle_from_file(const char *filepath, struct BlendFileReadReport *reports)
Definition: readblenentry.c:48
struct BlendHandle BlendHandle
Definition: BLO_readfile.h:35
void BLO_blendhandle_close(BlendHandle *bh)
struct BlendThumbnail * BLO_thumbnail_from_file(const char *filepath)
Definition: readfile.c:1563
ID and Library types, which are fundamental for sdna.
@ ICON_SIZE_PREVIEW
Definition: DNA_ID_enums.h:16
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
static const pxr::TfToken preview("preview", pxr::TfToken::Immortal)
struct ReportList * reports
Definition: BLO_readfile.h:80
static ImBuf * imb_thumb_load_from_blend_id(const char *blen_path, const char *blen_group, const char *blen_id)
Definition: thumbs_blend.c:33
ImBuf * IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id)
Definition: thumbs_blend.c:67
static ImBuf * imb_thumb_load_from_blendfile(const char *blen_path)
Definition: thumbs_blend.c:56