/* applies to render pipeline */ static void node_composit_exec_composite(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { /* image assigned to output */ /* stack order input sockets: col, alpha, z */ if(node->flag & NODE_DO_OUTPUT) { /* only one works on out */ Scene *scene= (Scene *)node->id; RenderData *rd= data; if(scene && (rd->scemode & R_DOCOMP)) { Render *re= RE_GetRender(scene->id.name); RenderResult *rr= RE_AcquireResultWrite(re); if(rr) { CompBuf *outbuf, *zbuf=NULL; if(rr->rectf) MEM_freeN(rr->rectf); outbuf= alloc_compbuf(rr->rectx, rr->recty, CB_RGBA, 1); if(in[1]->data==NULL) composit1_pixel_processor(node, outbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA); else composit2_pixel_processor(node, outbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL); if(in[2]->data) { if(rr->rectz) MEM_freeN(rr->rectz); zbuf= alloc_compbuf(rr->rectx, rr->recty, CB_VAL, 1); composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL); rr->rectz= zbuf->rect; zbuf->malloc= 0; free_compbuf(zbuf); } generate_preview(data, node, outbuf); /* we give outbuf to rr... */ rr->rectf= outbuf->rect; outbuf->malloc= 0; free_compbuf(outbuf); RE_ReleaseResult(re); /* signal for imageviewer to refresh (it converts to byte rects...) */ BKE_image_signal(BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"), NULL, IMA_SIGNAL_FREE); return; } else RE_ReleaseResult(re); } } if(in[0]->data) generate_preview(data, node, in[0]->data); }
static void node_composit_exec_colorbalance(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { CompBuf *cbuf= in[1]->data; CompBuf *stackbuf; /* stack order input: fac, image */ /* stack order output: image */ if(out[0]->hasoutput==0) return; if(in[0]->vec[0] == 0.f && in[0]->data == NULL) { out[0]->data = pass_on_compbuf(cbuf); return; } { NodeColorBalance *n= (NodeColorBalance *)node->storage; int c; for (c = 0; c < 3; c++) { n->lift_lgg[c] = 2.0f - n->lift[c]; n->gamma_inv[c] = (n->gamma[c] != 0.0f) ? 1.0f/n->gamma[c] : 1000000.0f; } } if (cbuf) { stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* create output based on image input */ if (node->custom1 == 0) { /* lift gamma gain */ if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) { composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_colorbalance_lgg, CB_RGBA); } else { composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_colorbalance_lgg_fac, CB_RGBA, CB_VAL); } } else { /* offset/power/slope : ASC-CDL */ if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) { composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_colorbalance_cdl, CB_RGBA); } else { composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_colorbalance_cdl_fac, CB_RGBA, CB_VAL); } } out[0]->data=stackbuf; } }
static void node_composit_exec_valtorgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { /* stack order in: fac */ /* stack order out: col, alpha */ if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; if(node->storage) { /* input no image? then only color operation */ if(in[0]->data==NULL) { do_colorband(node->storage, in[0]->vec[0], out[0]->vec); } else { /* make output size of input image */ CompBuf *cbuf= in[0]->data; CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_colorband_composit, CB_VAL); out[0]->data= stackbuf; if(out[1]->hasoutput) out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A); } } }
static void node_composit_exec_huecorrect(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { CompBuf *cbuf= in[1]->data; CompBuf *stackbuf; /* stack order input: fac, image, black level, white level */ /* stack order output: image */ if(out[0]->hasoutput==0) return; if(in[0]->vec[0] == 0.f && in[0]->data == NULL) { out[0]->data = pass_on_compbuf(cbuf); return; } /* input no image? then only color operation */ if(in[1]->data==NULL) { do_huecorrect_fac(node, out[0]->vec, in[1]->vec, in[0]->vec); } if (cbuf) { stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* make output size of input image */ if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_huecorrect, CB_RGBA); else composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_huecorrect_fac, CB_RGBA, CB_VAL); out[0]->data= stackbuf; } }
static void node_composit_exec_setalpha(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { /* stack order out: RGBA image */ /* stack order in: col, alpha */ /* input no image? then only color operation */ if(in[0]->data==NULL && in[1]->data==NULL) { out[0]->vec[0] = in[0]->vec[0]; out[0]->vec[1] = in[0]->vec[1]; out[0]->vec[2] = in[0]->vec[2]; out[0]->vec[3] = in[1]->vec[0]; } else { /* make output size of input image */ CompBuf *cbuf= in[0]->data?in[0]->data:in[1]->data; CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ if(in[1]->data==NULL && in[1]->vec[0]==1.0f) { /* pass on image */ composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_copy_rgb, CB_RGBA); } else { /* send an compbuf or a value to set as alpha - composit2_pixel_processor handles choosing the right one */ composit2_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL); } out[0]->data= stackbuf; } }
static void node_composit_exec_invert(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { /* stack order in: fac, Image, Image */ /* stack order out: Image */ float *fac= in[0]->vec; if(out[0]->hasoutput==0) return; /* input no image? then only color operation */ if(in[1]->data==NULL && in[0]->data==NULL) { do_invert_fac(node, out[0]->vec, in[1]->vec, fac); } else { /* make output size of first available input image, or then size of fac */ CompBuf *cbuf= in[1]->data?in[1]->data:in[0]->data; /* if neither RGB or A toggled on, pass through */ if (node->custom1 != 0) { CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ if (fac[0] < 1.0f || in[0]->data!=NULL) composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, fac, do_invert_fac, CB_RGBA, CB_VAL); else composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_invert, CB_RGBA); out[0]->data= stackbuf; return; } else { out[0]->data = pass_on_compbuf(cbuf); return; } } }
/* generates normal, does dot product */ static void node_composit_exec_normal(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { bNodeSocket *sock= node->outputs.first; float *nor= ((bNodeSocketValueVector*)sock->default_value)->value; /* stack order input: normal */ /* stack order output: normal, value */ /* input no image? then only vector op */ if(in[0]->data==NULL) { VECCOPY(out[0]->vec, nor); /* render normals point inside... the widget points outside */ out[1]->vec[0]= -INPR(out[0]->vec, in[0]->vec); } else if(out[1]->hasoutput) { /* make output size of input image */ CompBuf *cbuf= in[0]->data; CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_normal, CB_VEC3); out[1]->data= stackbuf; } }
static void node_composit_exec_curve_rgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { /* stack order input: fac, image, black level, white level */ /* stack order output: image */ if (out[0]->hasoutput==0) return; curvemapping_initialize(node->storage); /* input no image? then only color operation */ if (in[1]->data==NULL) { curvemapping_evaluateRGBF(node->storage, out[0]->vec, in[1]->vec); } else { /* make output size of input image */ CompBuf *cbuf= in[1]->data; CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ curvemapping_set_black_white(node->storage, in[2]->vec, in[3]->vec); if (in[0]->data==NULL && in[0]->vec[0] == 1.0f) composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_curves, CB_RGBA); else composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_curves_fac, CB_RGBA, CB_VAL); out[0]->data= stackbuf; } }
static void node_composit_exec_distance_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { /* * Loosely based on the Sequencer chroma key plug-in, but enhanced to work in other color spaces and * uses a different difference function (suggested in forums of vfxtalk.com). */ CompBuf *workbuf; CompBuf *inbuf; NodeChroma *c; /*is anything connected?*/ if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return; /*must have an image imput*/ if (in[0]->data==NULL) return; inbuf=typecheck_compbuf(in[0]->data, CB_RGBA); c=node->storage; workbuf=dupalloc_compbuf(inbuf); /*use the input color*/ c->key[0] = in[1]->vec[0]; c->key[1] = in[1]->vec[1]; c->key[2] = in[1]->vec[2]; /* work in RGB color space */ if (c->channel == 1) { /* note, processor gets a keyvals array passed on as buffer constant */ composit1_pixel_processor(node, workbuf, workbuf, in[0]->vec, do_distance_matte, CB_RGBA); } /* work in YCbCr color space */ else { composit1_pixel_processor(node, workbuf, workbuf, in[0]->vec, do_chroma_distance_matte, CB_RGBA); } out[0]->data=workbuf; if (out[1]->hasoutput) out[1]->data=valbuf_from_rgbabuf(workbuf, CHAN_A); generate_preview(data, node, workbuf); if (inbuf!=in[0]->data) free_compbuf(inbuf); }
static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { CompBuf *cbuf; CompBuf *outbuf; if(in[0]->hasinput==0) return; if(in[0]->data==NULL) return; if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); outbuf=dupalloc_compbuf(cbuf); /*convert to colorspace*/ switch(node->custom1) { case 1: /*RGB */ break; case 2: /*HSV*/ composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_hsva, CB_RGBA); break; case 3: /*YUV*/ composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA); break; case 4: /*YCC*/ composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_normalized_rgba_to_ycca2, CB_RGBA); break; default: break; } /*use the selected channel information to do the key */ composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_channel_matte, CB_RGBA); /*convert back to RGB colorspace in place*/ switch(node->custom1) { case 1: /*RGB*/ break; case 2: /*HSV*/ composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_hsva_to_rgba, CB_RGBA); break; case 3: /*YUV*/ composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA); break; case 4: /*YCC*/ composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_normalized_ycca_to_rgba2, CB_RGBA); break; default: break; } generate_preview(data, node, outbuf); out[0]->data=outbuf; if(out[1]->hasoutput) out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A); if(cbuf!=in[0]->data) free_compbuf(cbuf); }
static void node_composit_exec_luma_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { CompBuf *cbuf; CompBuf *outbuf; if(in[0]->hasinput==0) return; if(in[0]->data==NULL) return; if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); outbuf=dupalloc_compbuf(cbuf); composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA); composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_luma_matte, CB_RGBA); composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA); generate_preview(data, node, outbuf); out[0]->data=outbuf; if (out[1]->hasoutput) out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A); if(cbuf!=in[0]->data) free_compbuf(cbuf); }
static void node_composit_exec_chroma_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { CompBuf *cbuf; CompBuf *chromabuf; NodeChroma *c; if(in[0]->hasinput==0) return; if(in[0]->data==NULL) return; if(out[0]->hasoutput==0 && out[1]->hasoutput==0) return; cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); chromabuf= dupalloc_compbuf(cbuf); c=node->storage; /*convert rgbbuf to normalized chroma space*/ composit1_pixel_processor(node, chromabuf, cbuf, in[0]->vec, do_rgba_to_ycca_normalized, CB_RGBA); /*convert key to normalized chroma color space */ do_rgba_to_ycca_normalized(node, c->key, in[1]->vec); /*per pixel chroma key*/ composit1_pixel_processor(node, chromabuf, chromabuf, in[0]->vec, do_chroma_key, CB_RGBA); /*convert back*/ composit1_pixel_processor(node, chromabuf, chromabuf, in[0]->vec, do_ycca_to_rgba_normalized, CB_RGBA); out[0]->data= chromabuf; if(out[1]->hasoutput) out[1]->data= valbuf_from_rgbabuf(chromabuf, CHAN_A); generate_preview(data, node, chromabuf); if(cbuf!=in[0]->data) free_compbuf(cbuf); };
static void node_composit_exec_map_value(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { /* stack order in: valbuf */ /* stack order out: valbuf */ if(out[0]->hasoutput==0) return; /* input no image? then only value operation */ if(in[0]->data==NULL) { do_map_value(node, out[0]->vec, in[0]->vec); } else { /* make output size of input image */ CompBuf *cbuf= in[0]->data; CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_map_value, CB_VAL); out[0]->data= stackbuf; } }
static void node_composit_exec_sepyuva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { /* stack order out: bw channels */ /* stack order in: col */ /* input no image? then only color operation */ if(in[0]->data==NULL) { float y, u, v; rgb_to_yuv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &u, &v); out[0]->vec[0] = y; out[1]->vec[0] = u; out[2]->vec[0] = v; out[3]->vec[0] = in[0]->vec[3]; } else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) { /* make copy of buffer so input image doesn't get corrupted */ CompBuf *cbuf= dupalloc_compbuf(in[0]->data); CompBuf *cbuf2=typecheck_compbuf(cbuf, CB_RGBA); /* convert the RGB stackbuf to an YUV representation */ composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepyuva, CB_RGBA); /* separate each of those channels */ if(out[0]->hasoutput) out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R); if(out[1]->hasoutput) out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G); if(out[2]->hasoutput) out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B); if(out[3]->hasoutput) out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A); /*not used anymore */ if(cbuf2!=cbuf) free_compbuf(cbuf2); free_compbuf(cbuf); } }
static void node_composit_exec_color_spill(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { /* Originally based on the information from the book "The Art and Science of Digital Composition" and * discussions from vfxtalk.com .*/ CompBuf *cbuf; /* CompBuf *mask; */ /* UNUSED */ CompBuf *rgbbuf; CompBuf *spillmap; NodeColorspill *ncs; ncs=node->storage; /* early out for missing connections */ if(out[0]->hasoutput==0 ) return; if(in[0]->hasinput==0) return; if(in[0]->data==NULL) return; cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); /* mask= */ /* UNUSED */ typecheck_compbuf(in[1]->data, CB_VAL); spillmap=alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); rgbbuf=dupalloc_compbuf(cbuf); switch(node->custom1) { case 1: /*red spill*/ { switch(node->custom2) { case 0: /* simple limit */ { if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_red, CB_RGBA); } else { composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_red_fac, CB_RGBA, CB_VAL); } break; } case 1: /* average limit */ { if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_red, CB_RGBA); } else { composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_red_fac, CB_RGBA, CB_VAL); } break; } } if(ncs->unspill==0) { ncs->uspillr=1.0f; ncs->uspillg=0.0f; ncs->uspillb=0.0f; } composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_red, CB_RGBA, CB_VAL); break; } case 2: /*green spill*/ { switch(node->custom2) { case 0: /* simple limit */ { if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_green, CB_RGBA); } else { composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_green_fac, CB_RGBA, CB_VAL); } break; } case 1: /* average limit */ { if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_green, CB_RGBA); } else { composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_green_fac, CB_RGBA, CB_VAL); } break; } } if(ncs->unspill==0) { ncs->uspillr=0.0f; ncs->uspillg=1.0f; ncs->uspillb=0.0f; } composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_green, CB_RGBA, CB_VAL); break; } case 3: /*blue spill*/ { switch(node->custom2) { case 0: /* simple limit */ { if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_blue, CB_RGBA); } else { composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_blue_fac, CB_RGBA, CB_VAL); } break; } case 1: /* average limit */ { if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) { composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_blue, CB_RGBA); } else { composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_blue_fac, CB_RGBA, CB_VAL); } break; } } if(ncs->unspill==0) { ncs->uspillr=0.0f; ncs->uspillg=0.0f; ncs->uspillb=1.0f; } composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_blue, CB_RGBA, CB_VAL); break; } default: break; } out[0]->data=rgbbuf; if(cbuf!=in[0]->data) free_compbuf(cbuf); free_compbuf(spillmap); }
static void node_composit_exec_sepycca(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { /* input no image? then only color operation */ if(in[0]->data==NULL) { float y, cb, cr; switch(node->custom1) { case 1: rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_ITU_BT709); break; case 2: rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_JFIF_0_255); break; case 0: default: rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_ITU_BT601); break; } /*divided by 255 to normalize for viewing in */ out[0]->vec[0] = y/255.0; out[1]->vec[0] = cb/255.0; out[2]->vec[0] = cr/255.0; out[3]->vec[0] = in[0]->vec[3]; } else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) { /* make copy of buffer so input buffer doesn't get corrupted */ CompBuf *cbuf= dupalloc_compbuf(in[0]->data); CompBuf *cbuf2=typecheck_compbuf(cbuf, CB_RGBA); /* convert the RGB stackbuf to an HSV representation */ switch(node->custom1) { case 1: composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_709, CB_RGBA); break; case 2: composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_jfif, CB_RGBA); break; case 0: default: composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_601, CB_RGBA); break; } /* separate each of those channels */ if(out[0]->hasoutput) out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R); if(out[1]->hasoutput) out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G); if(out[2]->hasoutput) out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B); if(out[3]->hasoutput) out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A); /*not used anymore */ if(cbuf2!=cbuf) free_compbuf(cbuf2); free_compbuf(cbuf); } }
static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out)) { /* image assigned to output */ /* stack order input sockets: col, alpha, z */ if (node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */ RenderData *rd= data; Image *ima= (Image *)node->id; ImBuf *ibuf; CompBuf *cbuf, *tbuf; int rectx, recty; void *lock; BKE_image_user_frame_calc(node->storage, rd->cfra, 0); /* always returns for viewer image, but we check nevertheless */ ibuf= BKE_image_acquire_ibuf(ima, node->storage, &lock); if (ibuf==NULL) { printf("node_composit_exec_viewer error\n"); BKE_image_release_ibuf(ima, lock); return; } /* free all in ibuf */ imb_freerectImBuf(ibuf); imb_freerectfloatImBuf(ibuf); IMB_freezbuffloatImBuf(ibuf); /* get size */ tbuf= in[0]->data?in[0]->data:(in[1]->data?in[1]->data:in[2]->data); if (tbuf==NULL) { rectx= 320; recty= 256; } else { rectx= tbuf->x; recty= tbuf->y; } /* make ibuf, and connect to ima */ ibuf->x= rectx; ibuf->y= recty; imb_addrectfloatImBuf(ibuf); ima->ok= IMA_OK_LOADED; /* now we combine the input with ibuf */ cbuf= alloc_compbuf(rectx, recty, CB_RGBA, 0); /* no alloc*/ cbuf->rect= ibuf->rect_float; /* when no alpha, we can simply copy */ if (in[1]->data==NULL) { composit1_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA); } else composit2_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL); /* zbuf option */ if (in[2]->data) { CompBuf *zbuf= alloc_compbuf(rectx, recty, CB_VAL, 1); ibuf->zbuf_float= zbuf->rect; ibuf->mall |= IB_zbuffloat; composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL); /* free compbuf, but not the rect */ zbuf->malloc= 0; free_compbuf(zbuf); } BKE_image_release_ibuf(ima, lock); generate_preview(data, node, cbuf); free_compbuf(cbuf); } else if (in[0]->data) { generate_preview(data, node, in[0]->data); } }