static ID *read_named_part(FileData *fd, Main *mainvar, char *name, int idcode) { BHead *bhead; ID *id = NULL; bhead = blo_firstbhead(fd); while(bhead) { if(bhead->code==ENDB) break; else if(bhead->code==idcode) { // BHEAD+DATA dependancy id= (ID *)(bhead+1); if(strcmp(id->name+2, name)==0) { id= is_yet_read(mainvar, bhead); if(id==0) { read_libblock(fd, mainvar, bhead, LIB_TESTEXT, &id); printf("read lib block %s\n", id->name); return id; } break; } } bhead = blo_nextbhead(fd, bhead); } return NULL; } static struct PreviewImage* previewimg_get(ID *id) { PreviewImage* prv_img = NULL; if (GS(id->name) == ID_MA) { Material *mat = (Material*)id; prv_img = mat->preview; } else if (GS(id->name) == ID_TE) { Tex *tex = (Tex*)id; prv_img = tex->preview; } else if (GS(id->name) == ID_WO) { World *wo = (World*)id; prv_img = wo->preview; } else if (GS(id->name) == ID_LA) { Lamp *la = (Lamp*)id; prv_img = la->preview; } else if (GS(id->name) == ID_IM) { Image *img = (Image*)id; prv_img = img->preview; } return prv_img; } void BLO_library_get_previews(struct FileList *files, char *dir, int idcode) { FileData *fd= (FileData*) BIF_filelist_lib(files); Main *mainl; Main *m; Main *toremove; Base *centerbase; ID *id ; int totfile = BIF_filelist_numfiles(files); struct direntry* file = 0; int a; struct PreviewImage* img; struct ImBuf* ima; fd->mainlist.first= fd->mainlist.last= G.main; G.main->next= NULL; /* make mains */ blo_split_main(&fd->mainlist, G.main); /* which one do we need? */ mainl = blo_find_main(&fd->mainlist, dir, G.sce); mainl->versionfile= fd->fileversion; // needed for do_version for(a=0; arelname, idcode); if (id) { img = previewimg_get(id); if (img) { unsigned int w = img->w[PREVIEW_MIPMAP_LARGE]; unsigned int h = img->h[PREVIEW_MIPMAP_LARGE]; unsigned int *rect = img->rect[PREVIEW_MIPMAP_LARGE]; /* first allocate imbuf for copying preview into it */ if (w > 0 && h > 0 && rect) { ima = IMB_allocImBuf(w, h, 32, IB_rect, 0); memcpy(ima->rect, rect, w*h*sizeof(unsigned int)); file->image = ima; file->flags |= IMAGEFILE; } } /* free_libblock(mainl, id); */ } } } m = &fd->mainlist.first; while ((toremove= m->next)) { BLI_remlink(&fd->mainlist, toremove); MEM_freeN(toremove); } }