static void image_user_change(bContext *C, void *iuser_v, void *unused) { Scene *scene = CTX_data_scene(C); BKE_image_user_calc_imanr(iuser_v, scene->r.cfra, 0); }
void draw_image_main(const bContext *C, ARegion *ar) { SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); Image *ima; ImBuf *ibuf; float zoomx, zoomy; bool show_viewer, show_render, show_paint, show_stereo3d, show_multilayer; void *lock; /* XXX can we do this in refresh? */ #if 0 what_image(sima); if (sima->image) { ED_image_get_aspect(sima->image, &xuser_asp, &yuser_asp); /* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */ if (sima->image->type == IMA_TYPE_COMPOSITE) { ImageUser *iuser = ntree_get_active_iuser(scene->nodetree); if (iuser) { BKE_image_user_calc_imanr(iuser, scene->r.cfra, 0); sima->iuser = *iuser; } } /* and we check for spare */ ibuf = ED_space_image_buffer(sima); } #endif /* retrieve the image and information about it */ ima = ED_space_image(sima); ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); show_viewer = (ima && ima->source == IMA_SRC_VIEWER) != 0; show_render = (show_viewer && ima->type == IMA_TYPE_R_RESULT) != 0; show_paint = (ima && (sima->mode == SI_MODE_PAINT) && (show_viewer == false) && (show_render == false)); show_stereo3d = (ima && (ima->flag & IMA_IS_STEREO) && (sima->iuser.flag & IMA_SHOW_STEREO)); show_multilayer = ima && BKE_image_is_multilayer(ima); if (show_viewer) { /* use locked draw for drawing viewer image buffer since the compositor * is running in separated thread and compositor could free this buffers. * other images are not modifying in such a way so they does not require * lock (sergey) */ BLI_lock_thread(LOCK_DRAW_IMAGE); } if (show_stereo3d) { if (show_multilayer) /* update multiindex and pass for the current eye */ BKE_image_multilayer_index(ima->rr, &sima->iuser); else BKE_image_multiview_index(ima, &sima->iuser); } ibuf = ED_space_image_acquire_buffer(sima, &lock); /* draw the image or grid */ if (ibuf == NULL) ED_region_grid_draw(ar, zoomx, zoomy); else if (sima->flag & SI_DRAW_TILE) draw_image_buffer_repeated(C, sima, ar, scene, ima, ibuf, zoomx, zoomy); else if (ima && (ima->tpageflag & IMA_TILES)) draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, 0.0f, 0.0, zoomx, zoomy); else draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy); /* paint helpers */ if (show_paint) draw_image_paint_helpers(C, ar, scene, zoomx, zoomy); /* XXX integrate this code */ #if 0 if (ibuf) { float xoffs = 0.0f, yoffs = 0.0f; if (image_preview_active(sa, &xim, &yim)) { xoffs = scene->r.disprect.xmin; yoffs = scene->r.disprect.ymin; glColor3ub(0, 0, 0); calc_image_view(sima, 'f'); myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax); glRectf(0.0f, 0.0f, 1.0f, 1.0f); glLoadIdentity(); } } #endif ED_space_image_release_buffer(sima, ibuf, lock); if (show_viewer) { BLI_unlock_thread(LOCK_DRAW_IMAGE); } /* render info */ if (ima && show_render) draw_render_info(C, sima->iuser.scene, ima, ar, zoomx, zoomy); }
static void node_composit_exec_splitviewer(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { /* image assigned to output */ /* stack order input sockets: image image */ if(in[0]->data==NULL || in[1]->data==NULL) return; if(node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */ Image *ima= (Image *)node->id; RenderData *rd= data; ImBuf *ibuf; CompBuf *cbuf, *buf1, *buf2, *mask; int x, y; float offset; buf1= typecheck_compbuf(in[0]->data, CB_RGBA); buf2= typecheck_compbuf(in[1]->data, CB_RGBA); BKE_image_user_calc_imanr(node->storage, rd->cfra, 0); /* always returns for viewer image, but we check nevertheless */ ibuf= BKE_image_get_ibuf(ima, node->storage); if(ibuf==NULL) { printf("node_composit_exec_viewer error\n"); return; } /* free all in ibuf */ imb_freerectImBuf(ibuf); imb_freerectfloatImBuf(ibuf); IMB_freezbuffloatImBuf(ibuf); /* make ibuf, and connect to ima */ ibuf->x= buf1->x; ibuf->y= buf1->y; imb_addrectfloatImBuf(ibuf); ima->ok= IMA_OK_LOADED; /* output buf */ cbuf= alloc_compbuf(buf1->x, buf1->y, CB_RGBA, 0); /* no alloc*/ cbuf->rect= ibuf->rect_float; /* mask buf */ mask= alloc_compbuf(buf1->x, buf1->y, CB_VAL, 1); /* Check which offset mode is selected and limit offset if needed */ if(node->custom2 == 0) { offset = buf1->x / 100.0f * node->custom1; CLAMP(offset, 0, buf1->x); } else { offset = buf1->y / 100.0f * node->custom1; CLAMP(offset, 0, buf1->y); } if(node->custom2 == 0) { for(y=0; y<buf1->y; y++) { float *fac= mask->rect + y*buf1->x; for(x=offset; x>0; x--, fac++) *fac= 1.0f; } } else { for(y=0; y<offset; y++) { float *fac= mask->rect + y*buf1->x; for(x=buf1->x; x>0; x--, fac++) *fac= 1.0f; } } composit3_pixel_processor(node, cbuf, buf1, in[0]->vec, buf2, in[1]->vec, mask, NULL, do_copy_split_rgba, CB_RGBA, CB_RGBA, CB_VAL); generate_preview(data, node, cbuf); free_compbuf(cbuf); free_compbuf(mask); if(in[0]->data != buf1) free_compbuf(buf1); if(in[1]->data != buf2) free_compbuf(buf2); } }
static void node_composit_exec_image(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { /* image assigned to output */ /* stack order input sockets: col, alpha */ if(node->id) { RenderData *rd= data; Image *ima= (Image *)node->id; ImageUser *iuser= (ImageUser *)node->storage; CompBuf *stackbuf= NULL; /* first set the right frame number in iuser */ BKE_image_user_calc_imanr(iuser, rd->cfra, 0); /* force a load, we assume iuser index will be set OK anyway */ if(ima->type==IMA_TYPE_MULTILAYER) BKE_image_get_ibuf(ima, iuser); if(ima->type==IMA_TYPE_MULTILAYER && ima->rr) { RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer); if(rl) { out[0]->data= stackbuf= compbuf_multilayer_get(rd, rl, ima, iuser, SCE_PASS_COMBINED); /* go over all layers */ outputs_multilayer_get(rd, rl, out, ima, iuser); } } else { stackbuf= node_composit_get_image(rd, ima, iuser); if (stackbuf) { /*respect image premul option*/ if (stackbuf->type==CB_RGBA && ima->flag & IMA_DO_PREMUL) { int i; float *pixel; /*first duplicate stackbuf->rect, since it's just a pointer to the source imbuf, and we don't want to change that.*/ stackbuf->rect = MEM_dupallocN(stackbuf->rect); /*premul the image*/ pixel = stackbuf->rect; for (i=0; i<stackbuf->x*stackbuf->y; i++, pixel += 4) { pixel[0] *= pixel[3]; pixel[1] *= pixel[3]; pixel[2] *= pixel[3]; } } /* put image on stack */ out[0]->data= stackbuf; if(out[2]->hasoutput) out[2]->data= node_composit_get_zimage(node, rd); } } /* alpha and preview for both types */ if(stackbuf) { if(out[1]->hasoutput) out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A); generate_preview(data, node, stackbuf); } } };
void draw_image_main(SpaceImage *sima, ARegion *ar, Scene *scene) { Image *ima; ImBuf *ibuf; float zoomx, zoomy; int show_viewer, show_render; void *lock; /* XXX can we do this in refresh? */ #if 0 what_image(sima); if(sima->image) { ED_image_aspect(sima->image, &xuser_asp, &yuser_asp); /* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */ if(sima->image->type==IMA_TYPE_COMPOSITE) { ImageUser *iuser= ntree_get_active_iuser(scene->nodetree); if(iuser) { BKE_image_user_calc_imanr(iuser, scene->r.cfra, 0); sima->iuser= *iuser; } } /* and we check for spare */ ibuf= ED_space_image_buffer(sima); } #endif /* retrieve the image and information about it */ ima= ED_space_image(sima); ED_space_image_zoom(sima, ar, &zoomx, &zoomy); ibuf= ED_space_image_acquire_buffer(sima, &lock); show_viewer= (ima && ima->source == IMA_SRC_VIEWER); show_render= (show_viewer && ima->type == IMA_TYPE_R_RESULT); /* draw the image or grid */ if(ibuf==NULL) draw_image_grid(ar, zoomx, zoomy); else if(sima->flag & SI_DRAW_TILE) draw_image_buffer_repeated(sima, ar, scene, ima, ibuf, zoomx, zoomy); else if(ima && (ima->tpageflag & IMA_TILES)) draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, 0.0f, 0.0, zoomx, zoomy); else draw_image_buffer(sima, ar, scene, ima, ibuf, 0.0f, 0.0f, zoomx, zoomy); /* paint helpers */ if(sima->flag & SI_DRAWTOOL) draw_image_paint_helpers(ar, scene, zoomx, zoomy); /* XXX integrate this code */ #if 0 if(ibuf) { float xoffs=0.0f, yoffs= 0.0f; if(image_preview_active(sa, &xim, &yim)) { xoffs= scene->r.disprect.xmin; yoffs= scene->r.disprect.ymin; glColor3ub(0,0,0); calc_image_view(sima, 'f'); myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax); glRectf(0.0f, 0.0f, 1.0f, 1.0f); glLoadIdentity(); } } #endif ED_space_image_release_buffer(sima, lock); /* render info */ if(ima && show_render) draw_render_info(scene, ima, ar); }