Files
test/source/blender/imbuf/intern/thumbs_blend.c
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00

74 lines
1.9 KiB
C

/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup imbuf
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "BLI_linklist.h"
#include "BLI_listbase.h" /* Needed due to import of BLO_readfile.h */
#include "BLI_utildefines.h"
#include "BLO_blend_defs.h"
#include "BLO_readfile.h"
#include "BKE_icons.h"
#include "BKE_idtype.h"
#include "BKE_main.h"
#include "DNA_ID.h" /* For preview images... */
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_thumbs.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,
const char *blen_group,
const char *blen_id)
{
ImBuf *ima = NULL;
BlendFileReadReport bf_reports = {.reports = NULL};
struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports);
if (libfiledata == NULL) {
return NULL;
}
int idcode = BKE_idtype_idcode_from_name(blen_group);
PreviewImage *preview = BLO_blendhandle_get_preview_for_id(libfiledata, idcode, blen_id);
BLO_blendhandle_close(libfiledata);
if (preview) {
ima = BKE_previewimg_to_imbuf(preview, ICON_SIZE_PREVIEW);
BKE_previewimg_freefunc(preview);
}
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);
}
return imb_thumb_load_from_blendfile(blen_path);
}