static void icon_preview_startjob(void *customdata, short *stop, short *do_update) { ShaderPreview *sp= customdata; ID *id= sp->id; short idtype= GS(id->name); if(idtype == ID_IM) { Image *ima= (Image*)id; ImBuf *ibuf= NULL; ImageUser iuser= {NULL}; /* ima->ok is zero when Image cannot load */ if(ima==NULL || ima->ok==0) return; /* setup dummy image user */ iuser.ok= iuser.framenr= 1; iuser.scene= sp->scene; /* elubie: this needs to be changed: here image is always loaded if not already there. Very expensive for large images. Need to find a way to only get existing ibuf */ ibuf = BKE_image_get_ibuf(ima, &iuser); if(ibuf==NULL || ibuf->rect==NULL) return; icon_copy_rect(ibuf, sp->sizex, sp->sizey, sp->pr_rect); *do_update= 1; } else if(idtype == ID_BR) { Brush *br= (Brush*)id; br->icon_imbuf= get_brush_icon(br); memset(sp->pr_rect, 0x888888, sp->sizex*sp->sizey*sizeof(unsigned int)); if(!(br->icon_imbuf) || !(br->icon_imbuf->rect)) return; icon_copy_rect(br->icon_imbuf, sp->sizex, sp->sizey, sp->pr_rect); *do_update= 1; } else { /* re-use shader job */ shader_preview_startjob(customdata, stop, do_update); /* world is rendered with alpha=0, so it wasn't displayed this could be render option for sky to, for later */ if(idtype == ID_WO) { set_alpha((char*)sp->pr_rect, sp->sizex, sp->sizey, 255); } else if(idtype == ID_MA) { Material* ma = (Material*)id; if(ma->material_type == MA_TYPE_HALO) set_alpha((char*)sp->pr_rect, sp->sizex, sp->sizey, 255); } } }
static void icon_preview_startjob(void *customdata, short *stop, short *do_update) { ShaderPreview *sp = customdata; if (sp->pr_method == PR_ICON_DEFERRED) { PreviewImage *prv = sp->owner; ImBuf *thumb; char *deferred_data = PRV_DEFERRED_DATA(prv); int source = deferred_data[0]; char *path = &deferred_data[1]; // printf("generating deferred %d×%d preview for %s\n", sp->sizex, sp->sizey, path); thumb = IMB_thumb_manage(path, THB_LARGE, source); if (thumb) { /* PreviewImage assumes premultiplied alhpa... */ IMB_premultiply_alpha(thumb); icon_copy_rect(thumb, sp->sizex, sp->sizey, sp->pr_rect); IMB_freeImBuf(thumb); } } else { ID *id = sp->id; short idtype = GS(id->name); if (idtype == ID_IM) { Image *ima = (Image *)id; ImBuf *ibuf = NULL; ImageUser iuser = {NULL}; /* ima->ok is zero when Image cannot load */ if (ima == NULL || ima->ok == 0) return; /* setup dummy image user */ iuser.ok = iuser.framenr = 1; iuser.scene = sp->scene; /* elubie: this needs to be changed: here image is always loaded if not * already there. Very expensive for large images. Need to find a way to * only get existing ibuf */ ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); if (ibuf == NULL || ibuf->rect == NULL) { BKE_image_release_ibuf(ima, ibuf, NULL); return; } icon_copy_rect(ibuf, sp->sizex, sp->sizey, sp->pr_rect); *do_update = true; BKE_image_release_ibuf(ima, ibuf, NULL); } else if (idtype == ID_BR) { Brush *br = (Brush *)id; br->icon_imbuf = get_brush_icon(br); memset(sp->pr_rect, 0x88, sp->sizex * sp->sizey * sizeof(unsigned int)); if (!(br->icon_imbuf) || !(br->icon_imbuf->rect)) return; icon_copy_rect(br->icon_imbuf, sp->sizex, sp->sizey, sp->pr_rect); *do_update = true; } else { /* re-use shader job */ shader_preview_startjob(customdata, stop, do_update); /* world is rendered with alpha=0, so it wasn't displayed * this could be render option for sky to, for later */ if (idtype == ID_WO) { set_alpha((char *)sp->pr_rect, sp->sizex, sp->sizey, 255); } else if (idtype == ID_MA) { Material *ma = (Material *)id; if (ma->material_type == MA_TYPE_HALO) set_alpha((char *)sp->pr_rect, sp->sizex, sp->sizey, 255); } } } }