Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/thumbs_blend.c
| Show All 19 Lines | |||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| /** \file blender/imbuf/intern/thumbs_blend.c | /** \file blender/imbuf/intern/thumbs_blend.c | ||||
| * \ingroup imbuf | * \ingroup imbuf | ||||
| */ | */ | ||||
| #include <stdlib.h> | |||||
| #include <string.h> | #include <string.h> | ||||
| #include "zlib.h" | #include "zlib.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_endian_switch.h" | #include "BLI_endian_switch.h" | ||||
| #include "BLI_fileops.h" | #include "BLI_fileops.h" | ||||
| #include "BLI_linklist.h" | |||||
| #include "BLO_blend_defs.h" | #include "BLO_blend_defs.h" | ||||
| #include "BLO_readfile.h" | |||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_idcode.h" | |||||
| #include "BKE_icons.h" | |||||
| #include "DNA_ID.h" /* For preview images... */ | |||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_thumbs.h" | #include "IMB_thumbs.h" | ||||
| /* extracts the thumbnail from between the 'REND' and the 'GLOB' | /* extracts the thumbnail from between the 'REND' and the 'GLOB' | ||||
| * chunks of the header, don't use typical blend loader because its too slow */ | * chunks of the header, don't use typical blend loader because its too slow */ | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | if (bhead[0] == TEST) { | ||||
| } | } | ||||
| return img; | return img; | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ImBuf *IMB_thumb_load_blend(const char *path) | ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id) | ||||
| { | { | ||||
| if (blen_group && blen_id) { | |||||
| LinkNode *ln, *names, *lp, *previews = NULL; | |||||
| struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, NULL); | |||||
| int idcode = BKE_idcode_from_name(blen_group); | |||||
| int i, nprevs, nnames; | |||||
| if (libfiledata == NULL) { | |||||
| return NULL; | |||||
| } | |||||
| /* 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. */ | |||||
| names = BLO_blendhandle_get_datablock_names(libfiledata, idcode, &nnames); | |||||
| previews = BLO_blendhandle_get_previews(libfiledata, idcode, &nprevs); | |||||
| BLO_blendhandle_close(libfiledata); | |||||
| if (!previews || (nnames != nprevs)) { | |||||
| if (previews != 0) { | |||||
| /* No previews at all is not a bug! */ | |||||
| printf("%s: error, found %d items, %d previews\n", __func__, nnames, nprevs); | |||||
| } | |||||
| BLI_linklist_free(previews, BKE_previewimg_freefunc); | |||||
| BLI_linklist_free(names, free); | |||||
| 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)) { | |||||
| ImBuf *ima = NULL; | |||||
| if (img) { | |||||
| unsigned int w = img->w[ICON_SIZE_PREVIEW]; | |||||
| unsigned int h = img->h[ICON_SIZE_PREVIEW]; | |||||
| unsigned int *rect = img->rect[ICON_SIZE_PREVIEW]; | |||||
| if (w > 0 && h > 0 && rect) { | |||||
| /* first allocate imbuf for copying preview into it */ | |||||
| ima = IMB_allocImBuf(w, h, 32, IB_rect); | |||||
| memcpy(ima->rect, rect, w * h * sizeof(unsigned int)); | |||||
| } | |||||
| } | |||||
| BLI_linklist_free(previews, BKE_previewimg_freefunc); | |||||
| BLI_linklist_free(names, free); | |||||
| return ima; | |||||
| } | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| else { | |||||
| gzFile gzfile; | gzFile gzfile; | ||||
| /* not necessarily a gzip */ | /* not necessarily a gzip */ | ||||
| gzfile = BLI_gzopen(path, "rb"); | gzfile = BLI_gzopen(blen_path, "rb"); | ||||
| if (NULL == gzfile) { | if (NULL == gzfile) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| else { | else { | ||||
| ImBuf *img = loadblend_thumb(gzfile); | ImBuf *img = loadblend_thumb(gzfile); | ||||
| /* read ok! */ | /* read ok! */ | ||||
| gzclose(gzfile); | gzclose(gzfile); | ||||
| return img; | return img; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| /* add a fake passepartout overlay to a byte buffer, use for blend file thumbnails */ | /* add a fake passepartout overlay to a byte buffer, use for blend file thumbnails */ | ||||
| #define MARGIN 2 | #define MARGIN 2 | ||||
| void IMB_thumb_overlay_blend(unsigned int *thumb, int width, int height, float aspect) | void IMB_thumb_overlay_blend(unsigned int *thumb, int width, int height, float aspect) | ||||
| { | { | ||||
| unsigned char *px = (unsigned char *)thumb; | unsigned char *px = (unsigned char *)thumb; | ||||
| int margin_l = MARGIN; | int margin_l = MARGIN; | ||||
| ▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines | |||||