Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-08-18 15:32:13 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-08-18 15:32:13 +0300
commita67a51ed55da8728ba2cc05f7b9bc026183080cb (patch)
tree59d66b967edb345abeb0831b383502c18cf491b8 /source/blender/imbuf/intern/thumbs_blend.c
parent2735f6fda66076c34f853afaccfc4dd78f66ca1f (diff)
IMB_thumb: Allow blen-handling func to also load datablock previews from .blend file.
Notes: * Not yet used, this is the last piece of 'side changes' before the big filebrowser commit. * We can probably be more effective here (like e.g. reading and storing all previews for a given group in thumbnails cache at once, instead of re-opening and parsing the whole file each time), but will do this later.
Diffstat (limited to 'source/blender/imbuf/intern/thumbs_blend.c')
-rw-r--r--source/blender/imbuf/intern/thumbs_blend.c81
1 files changed, 71 insertions, 10 deletions
diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c
index d7b9089c437..17d9f3d0735 100644
--- a/source/blender/imbuf/intern/thumbs_blend.c
+++ b/source/blender/imbuf/intern/thumbs_blend.c
@@ -25,6 +25,7 @@
*/
+#include <stdlib.h>
#include <string.h>
#include "zlib.h"
@@ -32,10 +33,16 @@
#include "BLI_utildefines.h"
#include "BLI_endian_switch.h"
#include "BLI_fileops.h"
+#include "BLI_linklist.h"
#include "BLO_blend_defs.h"
+#include "BLO_readfile.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.h"
@@ -121,22 +128,76 @@ static ImBuf *loadblend_thumb(gzFile gzfile)
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)
{
- gzFile gzfile;
- /* not necessarily a gzip */
- gzfile = BLI_gzopen(path, "rb");
+ if (blen_group && blen_id) {
+ LinkNode *ln, *names, *lp, *previews = NULL;
+ struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, NULL);
+ ImBuf *ima = NULL;
+ int idcode = BKE_idcode_from_name(blen_group);
+ int i, nprevs, nnames;
- if (NULL == gzfile) {
- return NULL;
+ 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 ima;
+ }
+
+ 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)) {
+ 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));
+ }
+ }
+ break;
+ }
+ }
+
+ BLI_linklist_free(previews, BKE_previewimg_freefunc);
+ BLI_linklist_free(names, free);
+ return ima;
}
else {
- ImBuf *img = loadblend_thumb(gzfile);
+ gzFile gzfile;
+ /* not necessarily a gzip */
+ gzfile = BLI_gzopen(blen_path, "rb");
- /* read ok! */
- gzclose(gzfile);
+ if (NULL == gzfile) {
+ return NULL;
+ }
+ else {
+ ImBuf *img = loadblend_thumb(gzfile);
- return img;
+ /* read ok! */
+ gzclose(gzfile);
+
+ return img;
+ }
}
}