diff options
Diffstat (limited to 'source/blender/nodes')
23 files changed, 1001 insertions, 952 deletions
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 8b2a5ebd263..2415c7842a7 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -76,6 +76,8 @@ set(SRC composite/nodes/node_composite_idMask.c composite/nodes/node_composite_image.c composite/nodes/node_composite_invert.c + composite/nodes/node_composite_keyingscreen.c + composite/nodes/node_composite_keying.c composite/nodes/node_composite_lensdist.c composite/nodes/node_composite_levels.c composite/nodes/node_composite_lummaMatte.c diff --git a/source/blender/nodes/NOD_composite.h b/source/blender/nodes/NOD_composite.h index f850ea91f12..33d6327ece1 100644 --- a/source/blender/nodes/NOD_composite.h +++ b/source/blender/nodes/NOD_composite.h @@ -105,6 +105,8 @@ void register_node_type_cmp_channel_matte(struct bNodeTreeType *ttype); void register_node_type_cmp_color_spill(struct bNodeTreeType *ttype); void register_node_type_cmp_luma_matte(struct bNodeTreeType *ttype); void register_node_type_cmp_doubleedgemask(struct bNodeTreeType *ttype); +void register_node_type_cmp_keyingscreen(struct bNodeTreeType *ttype); +void register_node_type_cmp_keying(struct bNodeTreeType *ttype); void register_node_type_cmp_translate(struct bNodeTreeType *ttype); void register_node_type_cmp_rotate(struct bNodeTreeType *ttype); diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c index 457322929b0..5813f4d479f 100644 --- a/source/blender/nodes/composite/node_composite_tree.c +++ b/source/blender/nodes/composite/node_composite_tree.c @@ -222,7 +222,7 @@ static void local_merge(bNodeTree *localtree, bNodeTree *ntree) copied back to original node */ if (lnode->storage) { if (lnode->new_node->storage) - BKE_tracking_distortion_destroy(lnode->new_node->storage); + BKE_tracking_distortion_free(lnode->new_node->storage); lnode->new_node->storage= BKE_tracking_distortion_copy(lnode->storage); } diff --git a/source/blender/nodes/composite/node_composite_util.c b/source/blender/nodes/composite/node_composite_util.c index ff223ac83cf..afd10d96e99 100644 --- a/source/blender/nodes/composite/node_composite_util.c +++ b/source/blender/nodes/composite/node_composite_util.c @@ -1022,7 +1022,7 @@ void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2) for (y=0; y<in2->y; y++) { colp = (fRGB*)&in2->rect[y*in2->x*in2->type]; for (x=0; x<in2->x; x++) - fRGB_add(wt, colp[x]); + add_v3_v3(wt, colp[x]); } if (wt[0] != 0.f) wt[0] = 1.f/wt[0]; if (wt[1] != 0.f) wt[1] = 1.f/wt[1]; @@ -1030,7 +1030,7 @@ void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2) for (y=0; y<in2->y; y++) { colp = (fRGB*)&in2->rect[y*in2->x*in2->type]; for (x=0; x<in2->x; x++) - fRGB_colormult(colp[x], wt); + mul_v3_v3(colp[x], wt); } // copy image data, unpacking interleaved RGBA into separate channels @@ -1279,14 +1279,14 @@ CompBuf* qd_downScaledCopy(CompBuf* src, int scale) xx = x*scale; mx = xx + scale; if (mx > src->x) mx = src->x; - colsum[0] = colsum[1] = colsum[2] = 0.f; + zero_v3(colsum); for (sy=yy; sy<my; sy++) { fRGB* scolp = (fRGB*)&src->rect[sy*src->x*src->type]; for (sx=xx; sx<mx; sx++) - fRGB_add(colsum, scolp[sx]); + add_v3_v3(colsum, scolp[sx]); } - fRGB_mult(colsum, fscale); - fRGB_copy(fcolp[x], colsum); + mul_v3_fl(colsum, fscale); + copy_v3_v3(fcolp[x], colsum); } } } diff --git a/source/blender/nodes/composite/node_composite_util.h b/source/blender/nodes/composite/node_composite_util.h index cab60caaae7..8f772b19d5e 100644 --- a/source/blender/nodes/composite/node_composite_util.h +++ b/source/blender/nodes/composite/node_composite_util.h @@ -182,30 +182,8 @@ extern void node_ID_title_cb(void *node_v, void *unused_v); /* utility functions used by glare, tonemap and lens distortion */ /* soms macros for color handling */ typedef float fRGB[4]; -/* clear color */ -#define fRGB_clear(c) { c[0]=c[1]=c[2]=0.f; } (void)0 -/* copy c2 to c1 */ -#define fRGB_copy(c1, c2) { c1[0]=c2[0]; c1[1]=c2[1]; c1[2]=c2[2]; c1[3]=c2[3]; } (void)0 -/* add c2 to c1 */ -#define fRGB_add(c1, c2) { c1[0]+=c2[0]; c1[1]+=c2[1]; c1[2]+=c2[2]; } (void)0 -/* subtract c2 from c1 */ -#define fRGB_sub(c1, c2) { c1[0]-=c2[0]; c1[1]-=c2[1]; c1[2]-=c2[2]; } (void)0 -/* multiply c by float value s */ -#define fRGB_mult(c, s) { c[0]*=s; c[1]*=s; c[2]*=s; } (void)0 -/* multiply c2 by s and add to c1 */ -#define fRGB_madd(c1, c2, s) { c1[0]+=c2[0]*s; c1[1]+=c2[1]*s; c1[2]+=c2[2]*s; } (void)0 -/* multiply c2 by color c1 */ -#define fRGB_colormult(c, cs) { c[0]*=cs[0]; c[1]*=cs[1]; c[2]*=cs[2]; } (void)0 -/* multiply c2 by color c3 and add to c1 */ -#define fRGB_colormadd(c1, c2, c3) { c1[0]+=c2[0]*c3[0]; c1[1]+=c2[1]*c3[1]; c1[2]+=c2[2]*c3[2]; } (void)0 /* multiply c2 by color rgb, rgb as separate arguments */ #define fRGB_rgbmult(c, r, g, b) { c[0]*=(r); c[1]*=(g); c[2]*=(b); } (void)0 -/* swap colors c1 & c2 */ -#define fRGB_swap(c1, c2) { float _t=c1[0]; c1[0]=c2[0]; c2[0]=_t;\ - _t=c1[1]; c1[1]=c2[1]; c2[1]=_t;\ - _t=c1[2]; c1[2]=c2[2]; c2[2]=_t;\ - _t=c1[3]; c1[3]=c2[3]; c3[3]=_t;\ - } (void)0 void qd_getPixel(CompBuf* src, int x, int y, float* col); void qd_setPixel(CompBuf* src, int x, int y, float* col); diff --git a/source/blender/nodes/composite/nodes/node_composite_bilateralblur.c b/source/blender/nodes/composite/nodes/node_composite_bilateralblur.c index 196234d658f..62e8138f5e1 100644 --- a/source/blender/nodes/composite/nodes/node_composite_bilateralblur.c +++ b/source/blender/nodes/composite/nodes/node_composite_bilateralblur.c @@ -32,71 +32,71 @@ #include "node_composite_util.h" /* **************** BILATERALBLUR ******************** */ -static bNodeSocketTemplate cmp_node_bilateralblur_in[]= { +static bNodeSocketTemplate cmp_node_bilateralblur_in[] = { { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, { SOCK_RGBA, 1, N_("Determinator"), 1.0f, 1.0f, 1.0f, 1.0f}, { -1, 0, "" } }; -static bNodeSocketTemplate cmp_node_bilateralblur_out[]= { +static bNodeSocketTemplate cmp_node_bilateralblur_out[] = { { SOCK_RGBA, 0, N_("Image")}, { -1, 0, "" } }; #define INIT_C3 \ - mean0 = 1; \ - mean1[0] = src[0]; \ - mean1[1] = src[1]; \ - mean1[2] = src[2]; \ - mean1[3] = src[3]; \ - (void)0 + mean0 = 1; \ + mean1[0] = src[0]; \ + mean1[1] = src[1]; \ + mean1[2] = src[2]; \ + mean1[3] = src[3]; \ + (void)0 /* finds color distances */ #define COLOR_DISTANCE_C3(c1, c2) \ - ((c1[0] - c2[0])*(c1[0] - c2[0]) + \ - (c1[1] - c2[1])*(c1[1] - c2[1]) + \ - (c1[2] - c2[2])*(c1[2] - c2[2]) + \ - (c1[3] - c2[3])*(c1[3] - c2[3])) + ((c1[0] - c2[0]) * (c1[0] - c2[0]) + \ + (c1[1] - c2[1]) * (c1[1] - c2[1]) + \ + (c1[2] - c2[2]) * (c1[2] - c2[2]) + \ + (c1[3] - c2[3]) * (c1[3] - c2[3])) /* this is the main kernel function for comparing color distances - and adding them weighted to the final color */ + and adding them weighted to the final color */ #define KERNEL_ELEMENT_C3(k) \ - temp_color = src + deltas[k]; \ - ref_color = ref + deltas[k]; \ - w = weight_tab[k] + \ - (double)COLOR_DISTANCE_C3(ref, ref_color ) * i2sigma_color; \ - w = 1.0/(w*w + 1); \ - mean0 += w; \ - mean1[0] += (double)temp_color[0] * w; \ - mean1[1] += (double)temp_color[1] * w; \ - mean1[2] += (double)temp_color[2] * w; \ - mean1[3] += (double)temp_color[3] * w; \ - (void)0 + temp_color = src + deltas[k]; \ + ref_color = ref + deltas[k]; \ + w = weight_tab[k] + \ + (double)COLOR_DISTANCE_C3(ref, ref_color) * i2sigma_color; \ + w = 1.0 / (w * w + 1); \ + mean0 += w; \ + mean1[0] += (double)temp_color[0] * w; \ + mean1[1] += (double)temp_color[1] * w; \ + mean1[2] += (double)temp_color[2] * w; \ + mean1[3] += (double)temp_color[3] * w; \ + (void)0 /* write blurred values to image */ #define UPDATE_OUTPUT_C3 \ - mean0 = 1.0/mean0; \ - dest[x * pix + 0] = mean1[0] * mean0; \ - dest[x * pix + 1] = mean1[1] * mean0; \ - dest[x * pix + 2] = mean1[2] * mean0; \ - dest[x * pix + 3] = mean1[3] * mean0; \ - (void)0 + mean0 = 1.0 / mean0; \ + dest[x * pix + 0] = mean1[0] * mean0; \ + dest[x * pix + 1] = mean1[1] * mean0; \ + dest[x * pix + 2] = mean1[2] * mean0; \ + dest[x * pix + 3] = mean1[3] * mean0; \ + (void)0 /* initializes deltas for fast access to neighbor pixels */ -#define INIT_3X3_DELTAS( deltas, step, nch ) \ - ((deltas)[0] = (nch), (deltas)[1] = -(step) + (nch), \ - (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch), \ - (deltas)[4] = -(nch), (deltas)[5] = (step) - (nch), \ - (deltas)[6] = (step), (deltas)[7] = (step) + (nch)); \ - (void)0 +#define INIT_3X3_DELTAS(deltas, step, nch) \ + ((deltas)[0] = (nch), (deltas)[1] = -(step) + (nch), \ + (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch), \ + (deltas)[4] = -(nch), (deltas)[5] = (step) - (nch), \ + (deltas)[6] = (step), (deltas)[7] = (step) + (nch)); \ + (void)0 /* code of this node was heavily inspired by the smooth function of opencv library. * The main change is an optional image input */ static void node_composit_exec_bilateralblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { - NodeBilateralBlurData *nbbd= node->storage; - CompBuf *new, *source, *img= in[0]->data, *refimg= in[1]->data; + NodeBilateralBlurData *nbbd = node->storage; + CompBuf *new, *source, *img = in[0]->data, *refimg = in[1]->data; double mean0, w, i2sigma_color, i2sigma_space; double mean1[4]; double weight_tab[8]; @@ -104,46 +104,46 @@ static void node_composit_exec_bilateralblur(void *UNUSED(data), bNode *node, bN float sigma_color, sigma_space; int imgx, imgy, x, y, pix, i, step; int deltas[8]; - short found_determinator= 0; + short found_determinator = 0; if (img == NULL || out[0]->hasoutput == 0) return; if (img->type != CB_RGBA) { - img= typecheck_compbuf(in[0]->data, CB_RGBA); + img = typecheck_compbuf(in[0]->data, CB_RGBA); } - imgx= img->x; - imgy= img->y; - pix= img->type; - step= pix * imgx; + imgx = img->x; + imgy = img->y; + pix = img->type; + step = pix * imgx; if (refimg) { if (refimg->x == imgx && refimg->y == imgy) { if (ELEM3(refimg->type, CB_VAL, CB_VEC2, CB_VEC3)) { - refimg= typecheck_compbuf(in[1]->data, CB_RGBA); - found_determinator= 1; + refimg = typecheck_compbuf(in[1]->data, CB_RGBA); + found_determinator = 1; } } } else { - refimg= img; + refimg = img; } /* allocs */ - source= dupalloc_compbuf(img); - new= alloc_compbuf(imgx, imgy, pix, 1); + source = dupalloc_compbuf(img); + new = alloc_compbuf(imgx, imgy, pix, 1); /* accept image offsets from other nodes */ - new->xof= img->xof; - new->yof= img->yof; + new->xof = img->xof; + new->yof = img->yof; /* bilateral code properties */ - sigma_color= nbbd->sigma_color; - sigma_space= nbbd->sigma_space; + sigma_color = nbbd->sigma_color; + sigma_space = nbbd->sigma_space; - i2sigma_color= 1.0f / (sigma_color * sigma_color); - i2sigma_space= 1.0f / (sigma_space * sigma_space); + i2sigma_color = 1.0f / (sigma_color * sigma_color); + i2sigma_space = 1.0f / (sigma_space * sigma_space); INIT_3X3_DELTAS(deltas, step, pix); @@ -151,13 +151,13 @@ static void node_composit_exec_bilateralblur(void *UNUSED(data), bNode *node, bN weight_tab[1] = weight_tab[3] = weight_tab[5] = weight_tab[7] = i2sigma_space * 2; /* iterations */ - for (i= 0; i < nbbd->iter; i++) { - src= source->rect; - ref= refimg->rect; - dest= new->rect; + for (i = 0; i < nbbd->iter; i++) { + src = source->rect; + ref = refimg->rect; + dest = new->rect; /*goes through image, there are more loops for 1st/last line and all other lines*/ /*kernel element accumulates surrounding colors, which are then written with the update_output function*/ - for (x= 0; x < imgx; x++, src+= pix, ref+= pix) { + for (x = 0; x < imgx; x++, src += pix, ref += pix) { INIT_C3; KERNEL_ELEMENT_C3(6); @@ -175,10 +175,10 @@ static void node_composit_exec_bilateralblur(void *UNUSED(data), bNode *node, bN UPDATE_OUTPUT_C3; } - dest+= step; + dest += step; - for (y= 1; y < imgy - 1; y++, dest+= step, src+= pix, ref+= pix) { - x= 0; + for (y = 1; y < imgy - 1; y++, dest += step, src += pix, ref += pix) { + x = 0; INIT_C3; @@ -190,10 +190,10 @@ static void node_composit_exec_bilateralblur(void *UNUSED(data), bNode *node, bN UPDATE_OUTPUT_C3; - src+= pix; - ref+= pix; + src += pix; + ref += pix; - for (x= 1; x < imgx - 1; x++, src+= pix, ref+= pix) { + for (x = 1; x < imgx - 1; x++, src += pix, ref += pix) { INIT_C3; KERNEL_ELEMENT_C3(0); @@ -219,7 +219,7 @@ static void node_composit_exec_bilateralblur(void *UNUSED(data), bNode *node, bN UPDATE_OUTPUT_C3; } - for (x= 0; x < imgx; x++, src+= pix, ref+= pix) { + for (x = 0; x < imgx; x++, src += pix, ref += pix) { INIT_C3; KERNEL_ELEMENT_C3(2); @@ -249,17 +249,17 @@ static void node_composit_exec_bilateralblur(void *UNUSED(data), bNode *node, bN free_compbuf(refimg); } - out[0]->data= source; + out[0]->data = source; free_compbuf(new); } -static void node_composit_init_bilateralblur(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +static void node_composit_init_bilateralblur(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp)) { - NodeBilateralBlurData *nbbd= MEM_callocN(sizeof(NodeBilateralBlurData), "node bilateral blur data"); - node->storage= nbbd; - nbbd->sigma_color= 0.3; - nbbd->sigma_space= 5.0; + NodeBilateralBlurData *nbbd = MEM_callocN(sizeof(NodeBilateralBlurData), "node bilateral blur data"); + node->storage = nbbd; + nbbd->sigma_color = 0.3; + nbbd->sigma_space = 5.0; } void register_node_type_cmp_bilateralblur(bNodeTreeType *ttype) diff --git a/source/blender/nodes/composite/nodes/node_composite_blur.c b/source/blender/nodes/composite/nodes/node_composite_blur.c index f10e6bfe939..046623f5b26 100644 --- a/source/blender/nodes/composite/nodes/node_composite_blur.c +++ b/source/blender/nodes/composite/nodes/node_composite_blur.c @@ -34,14 +34,14 @@ #include "node_composite_util.h" /* **************** BLUR ******************** */ -static bNodeSocketTemplate cmp_node_blur_in[]= { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Size"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_blur_in[] = { + { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("Size"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + { -1, 0, "" } }; -static bNodeSocketTemplate cmp_node_blur_out[]= { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_blur_out[] = { + { SOCK_RGBA, 0, N_("Image")}, + { -1, 0, "" } }; static float *make_gausstab(int filtertype, int rad) @@ -55,14 +55,14 @@ static float *make_gausstab(int filtertype, int rad) sum = 0.0f; for (i = -rad; i <= rad; i++) { - val= RE_filter_value(filtertype, (float)i/(float)rad); + val = RE_filter_value(filtertype, (float)i / (float)rad); sum += val; - gausstab[i+rad] = val; + gausstab[i + rad] = val; } - sum= 1.0f/sum; - for (i=0; i<n; i++) - gausstab[i]*= sum; + sum = 1.0f / sum; + for (i = 0; i < n; i++) + gausstab[i] *= sum; return gausstab; } @@ -77,8 +77,8 @@ static float *make_bloomtab(int rad) bloomtab = (float *) MEM_mallocN(n * sizeof(float), "bloom"); for (i = -rad; i <= rad; i++) { - val = powf(1.0f - fabsf((float)i)/((float)rad), 4.0f); - bloomtab[i+rad] = val; + val = powf(1.0f - fabsf((float)i) / ((float)rad), 4.0f); + bloomtab[i + rad] = val; } return bloomtab; @@ -87,61 +87,61 @@ static float *make_bloomtab(int rad) /* both input images of same type, either 4 or 1 channel */ static void blur_single_image(bNode *node, CompBuf *new, CompBuf *img, float scale) { - NodeBlurData *nbd= node->storage; + NodeBlurData *nbd = node->storage; CompBuf *work; register float sum, val; float rval, gval, bval, aval; float *gausstab, *gausstabcent; - int rad, imgx= img->x, imgy= img->y; - int x, y, pix= img->type; + int rad, imgx = img->x, imgy = img->y; + int x, y, pix = img->type; int i, bigstep; float *src, *dest; /* helper image */ - work= alloc_compbuf(imgx, imgy, img->type, 1); /* allocs */ + work = alloc_compbuf(imgx, imgy, img->type, 1); /* allocs */ /* horizontal */ if (nbd->sizex == 0) { memcpy(work->rect, img->rect, sizeof(float) * img->type * imgx * imgy); } else { - rad = scale*(float)nbd->sizex; - if (rad>imgx/2) - rad= imgx/2; - else if (rad<1) - rad= 1; + rad = scale * (float)nbd->sizex; + if (rad > imgx / 2) + rad = imgx / 2; + else if (rad < 1) + rad = 1; - gausstab= make_gausstab(nbd->filtertype, rad); - gausstabcent= gausstab+rad; + gausstab = make_gausstab(nbd->filtertype, rad); + gausstabcent = gausstab + rad; for (y = 0; y < imgy; y++) { - float *srcd= img->rect + pix*(y*img->x); + float *srcd = img->rect + pix * (y * img->x); - dest = work->rect + pix*(y * img->x); + dest = work->rect + pix * (y * img->x); - for (x = 0; x < imgx ; x++) { - int minr= x-rad<0?-x:-rad; - int maxr= x+rad>imgx?imgx-x:rad; + for (x = 0; x < imgx; x++) { + int minr = x - rad < 0 ? -x : -rad; + int maxr = x + rad > imgx ? imgx - x : rad; - src= srcd + pix*(x+minr); + src = srcd + pix * (x + minr); - sum= gval = rval= bval= aval= 0.0f; - for (i= minr; i < maxr; i++) { - val= gausstabcent[i]; - sum+= val; + sum = gval = rval = bval = aval = 0.0f; + for (i = minr; i < maxr; i++) { + val = gausstabcent[i]; + sum += val; rval += val * (*src++); - if (pix==4) { + if (pix == 4) { gval += val * (*src++); bval += val * (*src++); aval += val * (*src++); } } - sum= 1.0f/sum; - *dest++ = rval*sum; - if (pix==4) { - *dest++ = gval*sum; - *dest++ = bval*sum; - *dest++ = aval*sum; + sum = 1.0f / sum; + *dest++ = rval * sum; + if (pix == 4) { + *dest++ = gval * sum; + *dest++ = bval * sum; + *dest++ = aval * sum; } } if (node->exec & NODE_BREAK) @@ -156,47 +156,47 @@ static void blur_single_image(bNode *node, CompBuf *new, CompBuf *img, float sca memcpy(new->rect, work->rect, sizeof(float) * img->type * imgx * imgy); } else { - rad = scale*(float)nbd->sizey; - if (rad>imgy/2) - rad= imgy/2; - else if (rad<1) - rad= 1; - - gausstab= make_gausstab(nbd->filtertype, rad); - gausstabcent= gausstab+rad; + rad = scale * (float)nbd->sizey; + if (rad > imgy / 2) + rad = imgy / 2; + else if (rad < 1) + rad = 1; + + gausstab = make_gausstab(nbd->filtertype, rad); + gausstabcent = gausstab + rad; - bigstep = pix*imgx; + bigstep = pix * imgx; for (x = 0; x < imgx; x++) { - float *srcd= work->rect + pix*x; + float *srcd = work->rect + pix * x; - dest = new->rect + pix*x; + dest = new->rect + pix * x; - for (y = 0; y < imgy ; y++) { - int minr= y-rad<0?-y:-rad; - int maxr= y+rad>imgy?imgy-y:rad; + for (y = 0; y < imgy; y++) { + int minr = y - rad < 0 ? -y : -rad; + int maxr = y + rad > imgy ? imgy - y : rad; - src= srcd + bigstep*(y+minr); + src = srcd + bigstep * (y + minr); - sum= gval = rval= bval= aval= 0.0f; - for (i= minr; i < maxr; i++) { - val= gausstabcent[i]; - sum+= val; + sum = gval = rval = bval = aval = 0.0f; + for (i = minr; i < maxr; i++) { + val = gausstabcent[i]; + sum += val; rval += val * src[0]; - if (pix==4) { + if (pix == 4) { gval += val * src[1]; bval += val * src[2]; aval += val * src[3]; } src += bigstep; } - sum= 1.0f/sum; - dest[0] = rval*sum; - if (pix==4) { - dest[1] = gval*sum; - dest[2] = bval*sum; - dest[3] = aval*sum; + sum = 1.0f / sum; + dest[0] = rval * sum; + if (pix == 4) { + dest[1] = gval * sum; + dest[2] = bval * sum; + dest[3] = aval * sum; } - dest+= bigstep; + dest += bigstep; } if (node->exec & NODE_BREAK) break; @@ -216,83 +216,83 @@ static void bloom_with_reference(CompBuf *new, CompBuf *img, CompBuf *UNUSED(ref float **maintabs; float *gausstabx, *gausstabcenty; float *gausstaby, *gausstabcentx; - int radx, rady, imgx= img->x, imgy= img->y; + int radx, rady, imgx = img->x, imgy = img->y; int x, y; int i, j; float *src, *dest, *wb; - wbuf= alloc_compbuf(imgx, imgy, CB_VAL, 1); + wbuf = alloc_compbuf(imgx, imgy, CB_VAL, 1); /* horizontal */ radx = (float)nbd->sizex; - if (radx>imgx/2) - radx= imgx/2; - else if (radx<1) - radx= 1; + if (radx > imgx / 2) + radx = imgx / 2; + else if (radx < 1) + radx = 1; /* vertical */ rady = (float)nbd->sizey; - if (rady>imgy/2) - rady= imgy/2; - else if (rady<1) - rady= 1; - - x= MAX2(radx, rady); - maintabs= MEM_mallocN(x*sizeof(void *), "gauss array"); - for (i= 0; i<x; i++) - maintabs[i]= make_bloomtab(i+1); + if (rady > imgy / 2) + rady = imgy / 2; + else if (rady < 1) + rady = 1; + + x = MAX2(radx, rady); + maintabs = MEM_mallocN(x * sizeof(void *), "gauss array"); + for (i = 0; i < x; i++) + maintabs[i] = make_bloomtab(i + 1); /* vars to store before we go */ // refd= ref->rect; - src= img->rect; + src = img->rect; - radxf= (float)radx; - radyf= (float)rady; + radxf = (float)radx; + radyf = (float)rady; for (y = 0; y < imgy; y++) { - for (x = 0; x < imgx ; x++, src+=4) {//, refd++) { + for (x = 0; x < imgx; x++, src += 4) { //, refd++) { // int refradx= (int)(refd[0]*radxf); // int refrady= (int)(refd[0]*radyf); - int refradx= (int)(radxf*0.3f*src[3]*(src[0]+src[1]+src[2])); - int refrady= (int)(radyf*0.3f*src[3]*(src[0]+src[1]+src[2])); - - if (refradx>radx) refradx= radx; - else if (refradx<1) refradx= 1; - if (refrady>rady) refrady= rady; - else if (refrady<1) refrady= 1; + int refradx = (int)(radxf * 0.3f * src[3] * (src[0] + src[1] + src[2])); + int refrady = (int)(radyf * 0.3f * src[3] * (src[0] + src[1] + src[2])); - if (refradx==1 && refrady==1) { - wb= wbuf->rect + ( y*imgx + x); - dest= new->rect + 4*( y*imgx + x); - wb[0]+= 1.0f; + if (refradx > radx) refradx = radx; + else if (refradx < 1) refradx = 1; + if (refrady > rady) refrady = rady; + else if (refrady < 1) refrady = 1; + + if (refradx == 1 && refrady == 1) { + wb = wbuf->rect + (y * imgx + x); + dest = new->rect + 4 * (y * imgx + x); + wb[0] += 1.0f; dest[0] += src[0]; dest[1] += src[1]; dest[2] += src[2]; dest[3] += src[3]; } else { - int minxr= x-refradx<0?-x:-refradx; - int maxxr= x+refradx>imgx?imgx-x:refradx; - int minyr= y-refrady<0?-y:-refrady; - int maxyr= y+refrady>imgy?imgy-y:refrady; - - float *destd= new->rect + 4*( (y + minyr)*imgx + x + minxr); - float *wbufd= wbuf->rect + ( (y + minyr)*imgx + x + minxr); - - gausstabx= maintabs[refradx-1]; - gausstabcentx= gausstabx+refradx; - gausstaby= maintabs[refrady-1]; - gausstabcenty= gausstaby+refrady; - - for (i= minyr; i < maxyr; i++, destd+= 4*imgx, wbufd+= imgx) { - dest= destd; - wb= wbufd; - for (j= minxr; j < maxxr; j++, dest+=4, wb++) { + int minxr = x - refradx < 0 ? -x : -refradx; + int maxxr = x + refradx > imgx ? imgx - x : refradx; + int minyr = y - refrady < 0 ? -y : -refrady; + int maxyr = y + refrady > imgy ? imgy - y : refrady; + + float *destd = new->rect + 4 * ( (y + minyr) * imgx + x + minxr); + float *wbufd = wbuf->rect + ( (y + minyr) * imgx + x + minxr); + + gausstabx = maintabs[refradx - 1]; + gausstabcentx = gausstabx + refradx; + gausstaby = maintabs[refrady - 1]; + gausstabcenty = gausstaby + refrady; + + for (i = minyr; i < maxyr; i++, destd += 4 * imgx, wbufd += imgx) { + dest = destd; + wb = wbufd; + for (j = minxr; j < maxxr; j++, dest += 4, wb++) { - val= gausstabcenty[i]*gausstabcentx[j]; - wb[0]+= val; + val = gausstabcenty[i] * gausstabcentx[j]; + wb[0] += val; dest[0] += val * src[0]; dest[1] += val * src[1]; dest[2] += val * src[2]; @@ -303,23 +303,23 @@ static void bloom_with_reference(CompBuf *new, CompBuf *img, CompBuf *UNUSED(ref } } - x= imgx*imgy; - dest= new->rect; - wb= wbuf->rect; + x = imgx * imgy; + dest = new->rect; + wb = wbuf->rect; while (x--) { - val= 1.0f/wb[0]; - dest[0]*= val; - dest[1]*= val; - dest[2]*= val; - dest[3]*= val; + val = 1.0f / wb[0]; + dest[0] *= val; + dest[1] *= val; + dest[2] *= val; + dest[3] *= val; wb++; - dest+= 4; + dest += 4; } free_compbuf(wbuf); - x= MAX2(radx, rady); - for (i= 0; i<x; i++) + x = MAX2(radx, rady); + for (i = 0; i < x; i++) MEM_freeN(maintabs[i]); MEM_freeN(maintabs); @@ -328,12 +328,12 @@ static void bloom_with_reference(CompBuf *new, CompBuf *img, CompBuf *UNUSED(ref #if 0 static float hexagon_filter(float fi, float fj) { - fi= fabs(fi); - fj= fabs(fj); + fi = fabs(fi); + fj = fabs(fj); - if (fj>0.33f) { - fj= (fj-0.33f)/0.66f; - if (fi+fj>1.0f) + if (fj > 0.33f) { + fj = (fj - 0.33f) / 0.66f; + if (fi + fj > 1.0f) return 0.0f; else return 1.0f; @@ -346,85 +346,85 @@ static float hexagon_filter(float fi, float fj) /* both images same type, either 1 or 4 channels */ static void bokeh_single_image(bNode *node, CompBuf *new, CompBuf *img, float fac) { - NodeBlurData *nbd= node->storage; + NodeBlurData *nbd = node->storage; register float val; float radxf, radyf; float *gausstab, *dgauss; - int radx, rady, imgx= img->x, imgy= img->y; - int x, y, pix= img->type; + int radx, rady, imgx = img->x, imgy = img->y; + int x, y, pix = img->type; int i, j, n; - float *src= NULL, *dest, *srcd= NULL; + float *src = NULL, *dest, *srcd = NULL; /* horizontal */ - radxf = fac*(float)nbd->sizex; - if (radxf>imgx/2.0f) - radxf= imgx/2.0f; - else if (radxf<1.0f) - radxf= 1.0f; + radxf = fac * (float)nbd->sizex; + if (radxf > imgx / 2.0f) + radxf = imgx / 2.0f; + else if (radxf < 1.0f) + radxf = 1.0f; /* vertical */ - radyf = fac*(float)nbd->sizey; - if (radyf>imgy/2.0f) - radyf= imgy/2.0f; - else if (radyf<1.0f) - radyf= 1.0f; + radyf = fac * (float)nbd->sizey; + if (radyf > imgy / 2.0f) + radyf = imgy / 2.0f; + else if (radyf < 1.0f) + radyf = 1.0f; - radx= ceil(radxf); - rady= ceil(radyf); + radx = ceil(radxf); + rady = ceil(radyf); - n = (2*radx+1)*(2*rady+1); + n = (2 * radx + 1) * (2 * rady + 1); /* create a full filter image */ - gausstab= MEM_mallocN(sizeof(float)*n, "filter tab"); - dgauss= gausstab; - val= 0.0f; - for (j=-rady; j<=rady; j++) { - for (i=-radx; i<=radx; i++, dgauss++) { - float fj= (float)j/radyf; - float fi= (float)i/radxf; - float dist= sqrt(fj*fj + fi*fi); - - //*dgauss= hexagon_filter(fi, fj); - *dgauss= RE_filter_value(nbd->filtertype, dist); + gausstab = MEM_mallocN(sizeof(float) * n, "filter tab"); + dgauss = gausstab; + val = 0.0f; + for (j = -rady; j <= rady; j++) { + for (i = -radx; i <= radx; i++, dgauss++) { + float fj = (float)j / radyf; + float fi = (float)i / radxf; + float dist = sqrt(fj * fj + fi * fi); - val+= *dgauss; + //*dgauss= hexagon_filter(fi, fj); + *dgauss = RE_filter_value(nbd->filtertype, dist); + + val += *dgauss; } } - if (val!=0.0f) { - val= 1.0f/val; - for (j= n -1; j>=0; j--) - gausstab[j]*= val; + if (val != 0.0f) { + val = 1.0f / val; + for (j = n - 1; j >= 0; j--) + gausstab[j] *= val; } - else gausstab[4]= 1.0f; - - for (y = -rady+1; y < imgy+rady-1; y++) { - - if (y<=0) srcd= img->rect; - else if (y<imgy) srcd+= pix*imgx; - else srcd= img->rect + pix*(imgy-1)*imgx; - - for (x = -radx+1; x < imgx+radx-1 ; x++) { - int minxr= x-radx<0?-x:-radx; - int maxxr= x+radx>=imgx?imgx-x-1:radx; - int minyr= y-rady<0?-y:-rady; - int maxyr= y+rady>imgy-1?imgy-y-1:rady; - - float *destd= new->rect + pix*( (y + minyr)*imgx + x + minxr); - float *dgausd= gausstab + (minyr+rady)*(2*radx+1) + minxr+radx; - - if (x<=0) src= srcd; - else if (x<imgx) src+= pix; - else src= srcd + pix*(imgx-1); - - for (i= minyr; i <=maxyr; i++, destd+= pix*imgx, dgausd+= 2*radx + 1) { - dest= destd; - dgauss= dgausd; - for (j= minxr; j <=maxxr; j++, dest+=pix, dgauss++) { - val= *dgauss; - if (val!=0.0f) { + else gausstab[4] = 1.0f; + + for (y = -rady + 1; y < imgy + rady - 1; y++) { + + if (y <= 0) srcd = img->rect; + else if (y < imgy) srcd += pix * imgx; + else srcd = img->rect + pix * (imgy - 1) * imgx; + + for (x = -radx + 1; x < imgx + radx - 1; x++) { + int minxr = x - radx < 0 ? -x : -radx; + int maxxr = x + radx >= imgx ? imgx - x - 1 : radx; + int minyr = y - rady < 0 ? -y : -rady; + int maxyr = y + rady > imgy - 1 ? imgy - y - 1 : rady; + + float *destd = new->rect + pix * ( (y + minyr) * imgx + x + minxr); + float *dgausd = gausstab + (minyr + rady) * (2 * radx + 1) + minxr + radx; + + if (x <= 0) src = srcd; + else if (x < imgx) src += pix; + else src = srcd + pix * (imgx - 1); + + for (i = minyr; i <= maxyr; i++, destd += pix * imgx, dgausd += 2 * radx + 1) { + dest = destd; + dgauss = dgausd; + for (j = minxr; j <= maxxr; j++, dest += pix, dgauss++) { + val = *dgauss; + if (val != 0.0f) { dest[0] += val * src[0]; - if (pix>1) { + if (pix > 1) { dest[1] += val * src[1]; dest[2] += val * src[2]; dest[3] += val * src[3]; @@ -444,116 +444,116 @@ static void bokeh_single_image(bNode *node, CompBuf *new, CompBuf *img, float fa /* reference has to be mapped 0-1, and equal in size */ static void blur_with_reference(bNode *node, CompBuf *new, CompBuf *img, CompBuf *ref) { - NodeBlurData *nbd= node->storage; + NodeBlurData *nbd = node->storage; CompBuf *blurbuf, *ref_use; register float sum, val; float rval, gval, bval, aval, radxf, radyf; float **maintabs; float *gausstabx, *gausstabcenty; float *gausstaby, *gausstabcentx; - int radx, rady, imgx= img->x, imgy= img->y; - int x, y, pix= img->type; + int radx, rady, imgx = img->x, imgy = img->y; + int x, y, pix = img->type; int i, j; float *src, *dest, *refd, *blurd; - float defcol[4] = {1.0f, 1.0f, 1.0f, 1.0f}; /* default color for compbuf_get_pixel */ - float proccol[4]; /* local color if compbuf is procedural */ + float defcol[4] = {1.0f, 1.0f, 1.0f, 1.0f}; /* default color for compbuf_get_pixel */ + float proccol[4]; /* local color if compbuf is procedural */ int refradx, refrady; - if (ref->x!=img->x || ref->y!=img->y) + if (ref->x != img->x || ref->y != img->y) return; - ref_use= typecheck_compbuf(ref, CB_VAL); + ref_use = typecheck_compbuf(ref, CB_VAL); /* trick is; we blur the reference image... but only works with clipped values*/ - blurbuf= alloc_compbuf(imgx, imgy, CB_VAL, 1); - blurbuf->xof= ref_use->xof; - blurbuf->yof= ref_use->yof; - blurd= blurbuf->rect; - refd= ref_use->rect; - for (x= imgx*imgy; x>0; x--, refd++, blurd++) { - if (refd[0]<0.0f) blurd[0]= 0.0f; - else if (refd[0]>1.0f) blurd[0]= 1.0f; - else blurd[0]= refd[0]; + blurbuf = alloc_compbuf(imgx, imgy, CB_VAL, 1); + blurbuf->xof = ref_use->xof; + blurbuf->yof = ref_use->yof; + blurd = blurbuf->rect; + refd = ref_use->rect; + for (x = imgx * imgy; x > 0; x--, refd++, blurd++) { + if (refd[0] < 0.0f) blurd[0] = 0.0f; + else if (refd[0] > 1.0f) blurd[0] = 1.0f; + else blurd[0] = refd[0]; } blur_single_image(node, blurbuf, blurbuf, 1.0f); /* horizontal */ radx = (float)nbd->sizex; - if (radx>imgx/2) - radx= imgx/2; - else if (radx<1) - radx= 1; + if (radx > imgx / 2) + radx = imgx / 2; + else if (radx < 1) + radx = 1; /* vertical */ rady = (float)nbd->sizey; - if (rady>imgy/2) - rady= imgy/2; - else if (rady<1) - rady= 1; - - x= MAX2(radx, rady); - maintabs= MEM_mallocN(x*sizeof(void *), "gauss array"); - for (i= 0; i<x; i++) - maintabs[i]= make_gausstab(nbd->filtertype, i+1); - - dest= new->rect; - radxf= (float)radx; - radyf= (float)rady; + if (rady > imgy / 2) + rady = imgy / 2; + else if (rady < 1) + rady = 1; + + x = MAX2(radx, rady); + maintabs = MEM_mallocN(x * sizeof(void *), "gauss array"); + for (i = 0; i < x; i++) + maintabs[i] = make_gausstab(nbd->filtertype, i + 1); + + dest = new->rect; + radxf = (float)radx; + radyf = (float)rady; for (y = 0; y < imgy; y++) { - for (x = 0; x < imgx ; x++, dest+=pix) { - refd= compbuf_get_pixel(blurbuf, defcol, proccol, x-blurbuf->xrad, y-blurbuf->yrad, blurbuf->xrad, blurbuf->yrad); - refradx= (int)(refd[0]*radxf); - refrady= (int)(refd[0]*radyf); - - if (refradx>radx) refradx= radx; - else if (refradx<1) refradx= 1; - if (refrady>rady) refrady= rady; - else if (refrady<1) refrady= 1; - - if (refradx==1 && refrady==1) { - src= img->rect + pix*( y*imgx + x); - if (pix==1) - dest[0]= src[0]; + for (x = 0; x < imgx; x++, dest += pix) { + refd = compbuf_get_pixel(blurbuf, defcol, proccol, x - blurbuf->xrad, y - blurbuf->yrad, blurbuf->xrad, blurbuf->yrad); + refradx = (int)(refd[0] * radxf); + refrady = (int)(refd[0] * radyf); + + if (refradx > radx) refradx = radx; + else if (refradx < 1) refradx = 1; + if (refrady > rady) refrady = rady; + else if (refrady < 1) refrady = 1; + + if (refradx == 1 && refrady == 1) { + src = img->rect + pix * (y * imgx + x); + if (pix == 1) + dest[0] = src[0]; else copy_v4_v4(dest, src); } else { - int minxr= x-refradx<0?-x:-refradx; - int maxxr= x+refradx>imgx?imgx-x:refradx; - int minyr= y-refrady<0?-y:-refrady; - int maxyr= y+refrady>imgy?imgy-y:refrady; - - float *srcd= img->rect + pix*( (y + minyr)*imgx + x + minxr); - - gausstabx= maintabs[refradx-1]; - gausstabcentx= gausstabx+refradx; - gausstaby= maintabs[refrady-1]; - gausstabcenty= gausstaby+refrady; + int minxr = x - refradx < 0 ? -x : -refradx; + int maxxr = x + refradx > imgx ? imgx - x : refradx; + int minyr = y - refrady < 0 ? -y : -refrady; + int maxyr = y + refrady > imgy ? imgy - y : refrady; - sum= gval = rval= bval= aval= 0.0f; - - for (i= minyr; i < maxyr; i++, srcd+= pix*imgx) { - src= srcd; - for (j= minxr; j < maxxr; j++, src+=pix) { + float *srcd = img->rect + pix * ( (y + minyr) * imgx + x + minxr); + + gausstabx = maintabs[refradx - 1]; + gausstabcentx = gausstabx + refradx; + gausstaby = maintabs[refrady - 1]; + gausstabcenty = gausstaby + refrady; + + sum = gval = rval = bval = aval = 0.0f; + + for (i = minyr; i < maxyr; i++, srcd += pix * imgx) { + src = srcd; + for (j = minxr; j < maxxr; j++, src += pix) { - val= gausstabcenty[i]*gausstabcentx[j]; - sum+= val; + val = gausstabcenty[i] * gausstabcentx[j]; + sum += val; rval += val * src[0]; - if (pix>1) { + if (pix > 1) { gval += val * src[1]; bval += val * src[2]; aval += val * src[3]; } } } - sum= 1.0f/sum; - dest[0] = rval*sum; - if (pix>1) { - dest[1] = gval*sum; - dest[2] = bval*sum; - dest[3] = aval*sum; + sum = 1.0f / sum; + dest[0] = rval * sum; + if (pix > 1) { + dest[1] = gval * sum; + dest[2] = bval * sum; + dest[3] = aval * sum; } } } @@ -563,46 +563,46 @@ static void blur_with_reference(bNode *node, CompBuf *new, CompBuf *img, CompBuf free_compbuf(blurbuf); - x= MAX2(radx, rady); - for (i= 0; i<x; i++) + x = MAX2(radx, rady); + for (i = 0; i < x; i++) MEM_freeN(maintabs[i]); MEM_freeN(maintabs); - if (ref_use!=ref) + if (ref_use != ref) free_compbuf(ref_use); } static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - CompBuf *new, *img= in[0]->data; - NodeBlurData *nbd= node->storage; + CompBuf *new, *img = in[0]->data; + NodeBlurData *nbd = node->storage; - if (img==NULL) return; + if (img == NULL) return; /* store image in size that is needed for absolute/relative conversions on ui level */ - nbd->image_in_width= img->x; - nbd->image_in_height= img->y; + nbd->image_in_width = img->x; + nbd->image_in_height = img->y; - if (out[0]->hasoutput==0) return; + if (out[0]->hasoutput == 0) return; if (nbd->relative) { - if (nbd->aspect==CMP_NODE_BLUR_ASPECT_NONE) { - nbd->sizex= (int)(nbd->percentx*0.01f*nbd->image_in_width); - nbd->sizey= (int)(nbd->percenty*0.01f*nbd->image_in_height); + if (nbd->aspect == CMP_NODE_BLUR_ASPECT_NONE) { + nbd->sizex = (int)(nbd->percentx * 0.01f * nbd->image_in_width); + nbd->sizey = (int)(nbd->percenty * 0.01f * nbd->image_in_height); } - else if (nbd->aspect==CMP_NODE_BLUR_ASPECT_Y) { - nbd->sizex= (int)(nbd->percentx*0.01f*nbd->image_in_width); - nbd->sizey= (int)(nbd->percenty*0.01f*nbd->image_in_width); + else if (nbd->aspect == CMP_NODE_BLUR_ASPECT_Y) { + nbd->sizex = (int)(nbd->percentx * 0.01f * nbd->image_in_width); + nbd->sizey = (int)(nbd->percenty * 0.01f * nbd->image_in_width); } - else if (nbd->aspect==CMP_NODE_BLUR_ASPECT_X) { - nbd->sizex= (int)(nbd->percentx*0.01f*nbd->image_in_height); - nbd->sizey= (int)(nbd->percenty*0.01f*nbd->image_in_height); + else if (nbd->aspect == CMP_NODE_BLUR_ASPECT_X) { + nbd->sizex = (int)(nbd->percentx * 0.01f * nbd->image_in_height); + nbd->sizey = (int)(nbd->percenty * 0.01f * nbd->image_in_height); } } - if (nbd->sizex==0 && nbd->sizey==0) { - new= pass_on_compbuf(img); - out[0]->data= new; + if (nbd->sizex == 0 && nbd->sizey == 0) { + new = pass_on_compbuf(img); + out[0]->data = new; } else if (nbd->filtertype == R_FILTER_FAST_GAUSS) { if (in[1]->vec[0] < 0.001f) { /* time node inputs can be a tiny value */ @@ -610,10 +610,10 @@ static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bN } else { // TODO: can this be mapped with reference, too? - const float sx = ((float)nbd->sizex*in[1]->vec[0])/2.0f, sy = ((float)nbd->sizey*in[1]->vec[0])/2.0f; + const float sx = ((float)nbd->sizex * in[1]->vec[0]) / 2.0f, sy = ((float)nbd->sizey * in[1]->vec[0]) / 2.0f; int c; - if ((img==NULL) || (out[0]->hasoutput==0)) return; + if ((img == NULL) || (out[0]->hasoutput == 0)) return; if (img->type == CB_VEC2) new = typecheck_compbuf(img, CB_VAL); @@ -623,16 +623,16 @@ static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bN new = dupalloc_compbuf(img); if ((sx == sy) && (sx > 0.f)) { - for (c=0; c<new->type; ++c) + for (c = 0; c < new->type; ++c) IIR_gauss(new, sx, c, 3); } else { if (sx > 0.f) { - for (c=0; c<new->type; ++c) + for (c = 0; c < new->type; ++c) IIR_gauss(new, sx, c, 1); } if (sy > 0.f) { - for (c=0; c<new->type; ++c) + for (c = 0; c < new->type; ++c) IIR_gauss(new, sy, c, 2); } } @@ -641,8 +641,8 @@ static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bN } else { /* All non fast gauss blur methods */ - if (img->type==CB_VEC2 || img->type==CB_VEC3) { - img= typecheck_compbuf(in[0]->data, CB_RGBA); + if (img->type == CB_VEC2 || img->type == CB_VEC3) { + img = typecheck_compbuf(in[0]->data, CB_RGBA); } /* if fac input, we do it different */ @@ -650,17 +650,17 @@ static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bN CompBuf *gammabuf; /* make output size of input image */ - new= alloc_compbuf(img->x, img->y, img->type, 1); /* allocs */ + new = alloc_compbuf(img->x, img->y, img->type, 1); /* allocs */ /* accept image offsets from other nodes */ new->xof = img->xof; new->yof = img->yof; if (nbd->gamma) { - gammabuf= dupalloc_compbuf(img); + gammabuf = dupalloc_compbuf(img); gamma_correct_compbuf(gammabuf, 0); } - else gammabuf= img; + else gammabuf = img; blur_with_reference(node, new, gammabuf, in[1]->data); @@ -670,30 +670,30 @@ static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bN } if (node->exec & NODE_BREAK) { free_compbuf(new); - new= NULL; + new = NULL; } - out[0]->data= new; + out[0]->data = new; } else { - if (in[1]->vec[0]<=0.001f) { /* time node inputs can be a tiny value */ - new= pass_on_compbuf(img); + if (in[1]->vec[0] <= 0.001f) { /* time node inputs can be a tiny value */ + new = pass_on_compbuf(img); } else { CompBuf *gammabuf; /* make output size of input image */ - new= alloc_compbuf(img->x, img->y, img->type, 1); /* allocs */ + new = alloc_compbuf(img->x, img->y, img->type, 1); /* allocs */ /* accept image offsets from other nodes */ new->xof = img->xof; new->yof = img->yof; if (nbd->gamma) { - gammabuf= dupalloc_compbuf(img); + gammabuf = dupalloc_compbuf(img); gamma_correct_compbuf(gammabuf, 0); } - else gammabuf= img; + else gammabuf = img; if (nbd->bokeh) bokeh_single_image(node, new, gammabuf, in[1]->vec[0]); @@ -708,28 +708,28 @@ static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bN } if (node->exec & NODE_BREAK) { free_compbuf(new); - new= NULL; + new = NULL; } } - out[0]->data= new; + out[0]->data = new; } - if (img!=in[0]->data) + if (img != in[0]->data) free_compbuf(img); } generate_preview(data, node, out[0]->data); } -static void node_composit_init_blur(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +static void node_composit_init_blur(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp)) { - node->storage= MEM_callocN(sizeof(NodeBlurData), "node blur data"); + node->storage = MEM_callocN(sizeof(NodeBlurData), "node blur data"); } void register_node_type_cmp_blur(bNodeTreeType *ttype) { static bNodeType ntype; - node_type_base(ttype, &ntype, CMP_NODE_BLUR, "Blur", NODE_CLASS_OP_FILTER, NODE_PREVIEW|NODE_OPTIONS); + node_type_base(ttype, &ntype, CMP_NODE_BLUR, "Blur", NODE_CLASS_OP_FILTER, NODE_PREVIEW | NODE_OPTIONS); node_type_socket_templates(&ntype, cmp_node_blur_in, cmp_node_blur_out); node_type_size(&ntype, 120, 80, 200); node_type_init(&ntype, node_composit_init_blur); diff --git a/source/blender/nodes/composite/nodes/node_composite_bokehblur.c b/source/blender/nodes/composite/nodes/node_composite_bokehblur.c index 6b24bdb5c52..222ac7a5cdf 100644 --- a/source/blender/nodes/composite/nodes/node_composite_bokehblur.c +++ b/source/blender/nodes/composite/nodes/node_composite_bokehblur.c @@ -36,20 +36,20 @@ #include "../node_composite_util.h" /* **************** BLUR ******************** */ -static bNodeSocketTemplate cmp_node_bokehblur_in[]= { - { SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Bokeh"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Size"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, - { SOCK_FLOAT, 1, N_("Bounding box"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_bokehblur_in[] = { + { SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { SOCK_RGBA, 1, N_("Bokeh"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("Size"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, + { SOCK_FLOAT, 1, N_("Bounding box"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } }; -static bNodeSocketTemplate cmp_node_bokehblur_out[]= { - { SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_bokehblur_out[] = { + { SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } }; -static void node_composit_init_bokehblur(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +static void node_composit_init_bokehblur(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp)) { node->custom3 = 4.0f; node->custom4 = 16.0f; diff --git a/source/blender/nodes/composite/nodes/node_composite_dilate.c b/source/blender/nodes/composite/nodes/node_composite_dilate.c index 8363d5928bf..2f139831cc9 100644 --- a/source/blender/nodes/composite/nodes/node_composite_dilate.c +++ b/source/blender/nodes/composite/nodes/node_composite_dilate.c @@ -35,13 +35,13 @@ /* **************** Dilate/Erode ******************** */ -static bNodeSocketTemplate cmp_node_dilateerode_in[]= { - { SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_dilateerode_in[] = { + { SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, + { -1, 0, "" } }; -static bNodeSocketTemplate cmp_node_dilateerode_out[]= { - { SOCK_FLOAT, 0, N_("Mask")}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_dilateerode_out[] = { + { SOCK_FLOAT, 0, N_("Mask")}, + { -1, 0, "" } }; static void morpho_dilate(CompBuf *cbuf) @@ -49,31 +49,31 @@ static void morpho_dilate(CompBuf *cbuf) int x, y; float *p, *rectf = cbuf->rect; - for (y=0; y < cbuf->y; y++) { - for (x=0; x < cbuf->x-1; x++) { - p = rectf + cbuf->x*y + x; - *p = MAX2(*p, *(p + 1)); + for (y = 0; y < cbuf->y; y++) { + for (x = 0; x < cbuf->x - 1; x++) { + p = rectf + cbuf->x * y + x; + *p = maxf(*p, *(p + 1)); } } - for (y=0; y < cbuf->y; y++) { - for (x=cbuf->x-1; x >= 1; x--) { - p = rectf + cbuf->x*y + x; - *p = MAX2(*p, *(p - 1)); + for (y = 0; y < cbuf->y; y++) { + for (x = cbuf->x - 1; x >= 1; x--) { + p = rectf + cbuf->x * y + x; + *p = maxf(*p, *(p - 1)); } } - for (x=0; x < cbuf->x; x++) { - for (y=0; y < cbuf->y-1; y++) { - p = rectf + cbuf->x*y + x; - *p = MAX2(*p, *(p + cbuf->x)); + for (x = 0; x < cbuf->x; x++) { + for (y = 0; y < cbuf->y - 1; y++) { + p = rectf + cbuf->x * y + x; + *p = maxf(*p, *(p + cbuf->x)); } } - for (x=0; x < cbuf->x; x++) { - for (y=cbuf->y-1; y >= 1; y--) { - p = rectf + cbuf->x*y + x; - *p = MAX2(*p, *(p - cbuf->x)); + for (x = 0; x < cbuf->x; x++) { + for (y = cbuf->y - 1; y >= 1; y--) { + p = rectf + cbuf->x * y + x; + *p = maxf(*p, *(p - cbuf->x)); } } } @@ -83,31 +83,31 @@ static void morpho_erode(CompBuf *cbuf) int x, y; float *p, *rectf = cbuf->rect; - for (y=0; y < cbuf->y; y++) { - for (x=0; x < cbuf->x-1; x++) { - p = rectf + cbuf->x*y + x; - *p = MIN2(*p, *(p + 1)); + for (y = 0; y < cbuf->y; y++) { + for (x = 0; x < cbuf->x - 1; x++) { + p = rectf + cbuf->x * y + x; + *p = minf(*p, *(p + 1)); } } - for (y=0; y < cbuf->y; y++) { - for (x=cbuf->x-1; x >= 1; x--) { - p = rectf + cbuf->x*y + x; - *p = MIN2(*p, *(p - 1)); + for (y = 0; y < cbuf->y; y++) { + for (x = cbuf->x - 1; x >= 1; x--) { + p = rectf + cbuf->x * y + x; + *p = minf(*p, *(p - 1)); } } - for (x=0; x < cbuf->x; x++) { - for (y=0; y < cbuf->y-1; y++) { - p = rectf + cbuf->x*y + x; - *p = MIN2(*p, *(p + cbuf->x)); + for (x = 0; x < cbuf->x; x++) { + for (y = 0; y < cbuf->y - 1; y++) { + p = rectf + cbuf->x * y + x; + *p = minf(*p, *(p + cbuf->x)); } } - for (x=0; x < cbuf->x; x++) { - for (y=cbuf->y-1; y >= 1; y--) { - p = rectf + cbuf->x*y + x; - *p = MIN2(*p, *(p - cbuf->x)); + for (x = 0; x < cbuf->x; x++) { + for (y = cbuf->y - 1; y >= 1; y--) { + p = rectf + cbuf->x * y + x; + *p = minf(*p, *(p - cbuf->x)); } } @@ -117,18 +117,17 @@ static void node_composit_exec_dilateerode(void *UNUSED(data), bNode *node, bNod { /* stack order in: mask */ /* stack order out: mask */ - if (out[0]->hasoutput==0) + if (out[0]->hasoutput == 0) return; /* input no image? then only color operation */ - if (in[0]->data==NULL) { - out[0]->vec[0] = out[0]->vec[1] = out[0]->vec[2] = 0.0f; - out[0]->vec[3] = 0.0f; + if (in[0]->data == NULL) { + zero_v4(out[0]->vec); } else { /* make output size of input image */ - CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_VAL); - CompBuf *stackbuf= dupalloc_compbuf(cbuf); + CompBuf *cbuf = typecheck_compbuf(in[0]->data, CB_VAL); + CompBuf *stackbuf = dupalloc_compbuf(cbuf); short i; if (node->custom2 > 0) { // positive, dilate @@ -140,10 +139,10 @@ static void node_composit_exec_dilateerode(void *UNUSED(data), bNode *node, bNod morpho_erode(stackbuf); } - if (cbuf!=in[0]->data) + if (cbuf != in[0]->data) free_compbuf(cbuf); - out[0]->data= stackbuf; + out[0]->data = stackbuf; } } diff --git a/source/blender/nodes/composite/nodes/node_composite_directionalblur.c b/source/blender/nodes/composite/nodes/node_composite_directionalblur.c index 395fa154a89..73e28658309 100644 --- a/source/blender/nodes/composite/nodes/node_composite_directionalblur.c +++ b/source/blender/nodes/composite/nodes/node_composite_directionalblur.c @@ -32,23 +32,23 @@ #include "node_composite_util.h" -static bNodeSocketTemplate cmp_node_dblur_in[]= { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.f}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_dblur_in[] = { + { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.f}, + { -1, 0, "" } }; -static bNodeSocketTemplate cmp_node_dblur_out[]= { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_dblur_out[] = { + { SOCK_RGBA, 0, N_("Image")}, + { -1, 0, "" } }; static CompBuf *dblur(bNode *node, CompBuf *img, int iterations, int wrap, - float center_x, float center_y, float dist, float angle, float spin, float zoom) + float center_x, float center_y, float dist, float angle, float spin, float zoom) { if ((dist != 0.f) || (spin != 0.f) || (zoom != 0.f)) { - void (*getpix)(CompBuf*, float, float, float*) = wrap ? qd_getPixelLerpWrap : qd_getPixelLerp; - const float a= angle; - const float itsc= 1.f / powf(2.f, (float)iterations); + void (*getpix)(CompBuf *, float, float, float *) = wrap ? qd_getPixelLerpWrap : qd_getPixelLerp; + const float a = angle; + const float itsc = 1.f / powf(2.f, (float)iterations); float D; float center_x_pix, center_y_pix; float tx, ty; @@ -56,36 +56,36 @@ static CompBuf *dblur(bNode *node, CompBuf *img, int iterations, int wrap, CompBuf *tmp; int i, j; - tmp= dupalloc_compbuf(img); + tmp = dupalloc_compbuf(img); - D= dist * sqrtf(img->x * img->x + img->y * img->y); - center_x_pix= center_x * img->x; - center_y_pix= center_y * img->y; + D = dist * sqrtf(img->x * img->x + img->y * img->y); + center_x_pix = center_x * img->x; + center_y_pix = center_y * img->y; - tx= itsc * D * cosf(a); - ty= -itsc * D * sinf(a); - sc= itsc * zoom; - rot= itsc * spin; + tx = itsc * D * cosf(a); + ty = -itsc *D *sinf(a); + sc = itsc * zoom; + rot = itsc * spin; /* blur the image */ - for (i= 0; i < iterations; ++i) { - const float cs= cosf(rot), ss= sinf(rot); - const float isc= 1.f / (1.f + sc); + for (i = 0; i < iterations; ++i) { + const float cs = cosf(rot), ss = sinf(rot); + const float isc = 1.f / (1.f + sc); unsigned int x, y; - float col[4]= {0, 0, 0, 0}; + float col[4] = {0, 0, 0, 0}; - for (y= 0; y < img->y; ++y) { - const float v= isc * (y - center_y_pix) + ty; + for (y = 0; y < img->y; ++y) { + const float v = isc * (y - center_y_pix) + ty; - for (x= 0; x < img->x; ++x) { - const float u= isc * (x - center_x_pix) + tx; - unsigned int p= (x + y * img->x) * img->type; + for (x = 0; x < img->x; ++x) { + const float u = isc * (x - center_x_pix) + tx; + unsigned int p = (x + y * img->x) * img->type; getpix(tmp, cs * u + ss * v + center_x_pix, cs * v - ss * u + center_y_pix, col); /* mix img and transformed tmp */ - for (j= 0; j < 4; ++j) { - img->rect[p + j]= 0.5f * (img->rect[p + j] + col[j]); + for (j = 0; j < 4; ++j) { + img->rect[p + j] = 0.5f * (img->rect[p + j] + col[j]); } } } @@ -109,8 +109,8 @@ static CompBuf *dblur(bNode *node, CompBuf *img, int iterations, int wrap, static void node_composit_exec_dblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { - NodeDBlurData *ndbd= node->storage; - CompBuf *new, *img= in[0]->data; + NodeDBlurData *ndbd = node->storage; + CompBuf *new, *img = in[0]->data; if ((img == NULL) || (out[0]->hasoutput == 0)) return; @@ -119,15 +119,15 @@ static void node_composit_exec_dblur(void *UNUSED(data), bNode *node, bNodeStack else new = dupalloc_compbuf(img); - out[0]->data= dblur(node, new, ndbd->iter, ndbd->wrap, ndbd->center_x, ndbd->center_y, ndbd->distance, ndbd->angle, ndbd->spin, ndbd->zoom); + out[0]->data = dblur(node, new, ndbd->iter, ndbd->wrap, ndbd->center_x, ndbd->center_y, ndbd->distance, ndbd->angle, ndbd->spin, ndbd->zoom); } -static void node_composit_init_dblur(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +static void node_composit_init_dblur(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp)) { - NodeDBlurData *ndbd= MEM_callocN(sizeof(NodeDBlurData), "node dblur data"); - node->storage= ndbd; - ndbd->center_x= 0.5; - ndbd->center_y= 0.5; + NodeDBlurData *ndbd = MEM_callocN(sizeof(NodeDBlurData), "node dblur data"); + node->storage = ndbd; + ndbd->center_x = 0.5; + ndbd->center_y = 0.5; } void register_node_type_cmp_dblur(bNodeTreeType *ttype) diff --git a/source/blender/nodes/composite/nodes/node_composite_glare.c b/source/blender/nodes/composite/nodes/node_composite_glare.c index 1e32d6f0461..17a23d4295e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_glare.c +++ b/source/blender/nodes/composite/nodes/node_composite_glare.c @@ -53,16 +53,16 @@ static void mixImages(CompBuf *dst, CompBuf *src, float mix) dcolp = (fRGB*)&dst->rect[y*dst->x*dst->type]; scolp = (fRGB*)&src->rect[y*dst->x*dst->type]; for (x=0; x<dst->x; x++) { - fRGB_copy(c1, dcolp[x]); - fRGB_copy(c2, scolp[x]); + copy_v3_v3(c1, dcolp[x]); + copy_v3_v3(c2, scolp[x]); c1[0] += mix*(c2[0] - c1[0]); c1[1] += mix*(c2[1] - c1[1]); c1[2] += mix*(c2[2] - c1[2]); if (c1[0] < 0.f) c1[0] = 0.f; if (c1[1] < 0.f) c1[1] = 0.f; if (c1[2] < 0.f) c1[2] = 0.f; - fRGB_mult(c1, mf); - fRGB_copy(dcolp[x], c1); + mul_v3_fl(c1, mf); + copy_v3_v3(dcolp[x], c1); } } } @@ -72,7 +72,7 @@ static void mixImages(CompBuf *dst, CompBuf *src, float mix) for (y=0; y<dst->y; y++) { dcolp = (fRGB*)&dst->rect[y*dst->x*dst->type]; for (x=0; x<dst->x; x++) { - fRGB_copy(c1, dcolp[x]); + copy_v3_v3(c1, dcolp[x]); qd_getPixelLerp(src, (x + 0.5f)*xr - 0.5f, (y + 0.5f)*yr - 0.5f, c2); c1[0] += mix*(c2[0] - c1[0]); c1[1] += mix*(c2[1] - c1[1]); @@ -80,8 +80,8 @@ static void mixImages(CompBuf *dst, CompBuf *src, float mix) if (c1[0] < 0.f) c1[0] = 0.f; if (c1[1] < 0.f) c1[1] = 0.f; if (c1[2] < 0.f) c1[2] = 0.f; - fRGB_mult(c1, mf); - fRGB_copy(dcolp[x], c1); + mul_v3_fl(c1, mf); + copy_v3_v3(dcolp[x], c1); } } } @@ -107,7 +107,7 @@ static CompBuf* BTP(CompBuf* src, float threshold, int scaledown) float* cr = bsrc->rect; for (y=0; y<bsrc->y; ++y) for (x=0; x<bsrc->x; ++x, cr+=4) { - if ((0.212671f*cr[0] + 0.71516f*cr[1] + 0.072169f*cr[2]) >= threshold) { + if (rgb_to_luma_y(cr) >= threshold) { cr[0] -= threshold, cr[1] -= threshold, cr[2] -= threshold; cr[0] = MAX2(cr[0], 0.f); cr[1] = MAX2(cr[1], 0.f); @@ -146,11 +146,11 @@ static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src) xm = x - i; xp = x + i; qd_getPixel(tbuf1, x, y, c); - fRGB_mult(c, f1); + mul_v3_fl(c, f1); qd_getPixel(tbuf1, (ndg->angle ? xm : x), ym, tc); - fRGB_madd(c, tc, f2); + madd_v3_v3fl(c, tc, f2); qd_getPixel(tbuf1, (ndg->angle ? xp : x), yp, tc); - fRGB_madd(c, tc, f2); + madd_v3_v3fl(c, tc, f2); qd_setPixel(tbuf1, x, y, c); } } @@ -162,11 +162,11 @@ static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src) xm = x - i; xp = x + i; qd_getPixel(tbuf1, x, y, c); - fRGB_mult(c, f1); + mul_v3_fl(c, f1); qd_getPixel(tbuf1, (ndg->angle ? xm : x), ym, tc); - fRGB_madd(c, tc, f2); + madd_v3_v3fl(c, tc, f2); qd_getPixel(tbuf1, (ndg->angle ? xp : x), yp, tc); - fRGB_madd(c, tc, f2); + madd_v3_v3fl(c, tc, f2); qd_setPixel(tbuf1, x, y, c); } } @@ -179,11 +179,11 @@ static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src) xm = x - i; xp = x + i; qd_getPixel(tbuf2, x, y, c); - fRGB_mult(c, f1); + mul_v3_fl(c, f1); qd_getPixel(tbuf2, xm, (ndg->angle ? yp : y), tc); - fRGB_madd(c, tc, f2); + madd_v3_v3fl(c, tc, f2); qd_getPixel(tbuf2, xp, (ndg->angle ? ym : y), tc); - fRGB_madd(c, tc, f2); + madd_v3_v3fl(c, tc, f2); qd_setPixel(tbuf2, x, y, c); } } @@ -195,11 +195,11 @@ static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src) xm = x - i; xp = x + i; qd_getPixel(tbuf2, x, y, c); - fRGB_mult(c, f1); + mul_v3_fl(c, f1); qd_getPixel(tbuf2, xm, (ndg->angle ? yp : y), tc); - fRGB_madd(c, tc, f2); + madd_v3_v3fl(c, tc, f2); qd_getPixel(tbuf2, xp, (ndg->angle ? ym : y), tc); - fRGB_madd(c, tc, f2); + madd_v3_v3fl(c, tc, f2); qd_setPixel(tbuf2, x, y, c); } } @@ -342,11 +342,11 @@ static void ghosts(NodeGlare* ndg, CompBuf* dst, CompBuf* src) s = (u-0.5f)*sc + 0.5f, t = (v-0.5f)*sc + 0.5f; qd_getPixelLerp(tbuf1, s*gbuf->x, t*gbuf->y, c); sm = smoothMask(s, t); - fRGB_mult(c, sm); + mul_v3_fl(c, sm); s = (u-0.5f)*isc + 0.5f, t = (v-0.5f)*isc + 0.5f; qd_getPixelLerp(tbuf2, s*gbuf->x - 0.5f, t*gbuf->y - 0.5f, tc); sm = smoothMask(s, t); - fRGB_madd(c, tc, sm); + madd_v3_v3fl(c, tc, sm); qd_setPixel(gbuf, x, y, c); } } @@ -363,9 +363,9 @@ static void ghosts(NodeGlare* ndg, CompBuf* dst, CompBuf* src) s = (u-0.5f)*scalef[np] + 0.5f; t = (v-0.5f)*scalef[np] + 0.5f; qd_getPixelLerp(gbuf, s*gbuf->x - 0.5f, t*gbuf->y - 0.5f, c); - fRGB_colormult(c, cm[np]); + mul_v3_v3(c, cm[np]); sm = smoothMask(s, t)*0.25f; - fRGB_madd(tc, c, sm); + madd_v3_v3fl(tc, c, sm); } p = (x + y*tbuf1->x)*tbuf1->type; tbuf1->rect[p] += tc[0]; @@ -413,7 +413,7 @@ static void fglow(NodeGlare* ndg, CompBuf* dst, CompBuf* src) //w = (1.f-fabs(u))*(1.f-fabs(v)); // actually, Hanning window is ok, cos^2 for some reason is slower w = (0.5f + 0.5f*cos((double)u*M_PI))*(0.5f + 0.5f*cos((double)v*M_PI)); - fRGB_mult(fcol, w); + mul_v3_fl(fcol, w); qd_setPixel(ckrn, x, y, fcol); } } diff --git a/source/blender/nodes/composite/nodes/node_composite_keying.c b/source/blender/nodes/composite/nodes/node_composite_keying.c new file mode 100644 index 00000000000..f37c3686e2b --- /dev/null +++ b/source/blender/nodes/composite/nodes/node_composite_keying.c @@ -0,0 +1,96 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2011 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation, + * Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/nodes/composite/nodes/node_composite_keying.c + * \ingroup cmpnodes + */ + +#include "BLF_translation.h" + +#include "DNA_movieclip_types.h" + +#include "BKE_movieclip.h" + +#include "BLI_listbase.h" +#include "BLI_math_base.h" +#include "BLI_math_color.h" +#include "BLI_voronoi.h" + +#include "node_composite_util.h" + +/* **************** Translate ******************** */ + +static bNodeSocketTemplate cmp_node_keying_in[] = { + { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { SOCK_RGBA, 1, "Key Color", 1.0f, 1.0f, 1.0f, 1.0f}, + { SOCK_FLOAT, 1, "Garbage Matte", 0.0f, 1.0f, 1.0f, 1.0f}, + { SOCK_FLOAT, 1, "Core Matte", 0.0f, 1.0f, 1.0f, 1.0f}, + { -1, 0, "" } +}; + +static bNodeSocketTemplate cmp_node_keying_out[] = { + { SOCK_RGBA, 0, "Image"}, + { SOCK_FLOAT, 0, "Matte"}, + { SOCK_FLOAT, 0, "Edges"}, + { -1, 0, "" } +}; + +static void exec(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) +{ +} + +static void node_composit_init_keying(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +{ + NodeKeyingData *data; + + data = MEM_callocN(sizeof(NodeKeyingData), "node keying data"); + + data->screen_balance = 0.5f; + data->despill_factor = 1.0f; + data->edge_kernel_radius = 3; + data->edge_kernel_tolerance = 0.1f; + data->clip_white = 1.0f; + data->clip_black = 0.0f; + data->clip_white = 1.0f; + + node->storage = data; +} + +void register_node_type_cmp_keying(bNodeTreeType *ttype) +{ + static bNodeType ntype; + + node_type_base(ttype, &ntype, CMP_NODE_KEYING, "Keying", NODE_CLASS_MATTE, NODE_OPTIONS); + node_type_socket_templates(&ntype, cmp_node_keying_in, cmp_node_keying_out); + node_type_size(&ntype, 140, 100, 320); + node_type_init(&ntype, node_composit_init_keying); + node_type_storage(&ntype, "NodeKeyingData", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, exec); + + nodeRegisterType(ttype, &ntype); +} diff --git a/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c b/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c new file mode 100644 index 00000000000..73423e2bdd3 --- /dev/null +++ b/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c @@ -0,0 +1,202 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2011 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Blender Foundation, + * Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/nodes/composite/nodes/node_composite_keyingscreen.c + * \ingroup cmpnodes + */ + +#include "BLF_translation.h" + +#include "DNA_movieclip_types.h" + +#include "BKE_movieclip.h" + +#include "BLI_listbase.h" +#include "BLI_math_base.h" +#include "BLI_math_color.h" +#include "BLI_voronoi.h" + +#include "node_composite_util.h" + +/* **************** Translate ******************** */ + +static bNodeSocketTemplate cmp_node_keyingscreen_out[] = { + { SOCK_RGBA, 0, "Screen"}, + { -1, 0, "" } +}; + + +static void compute_gradient_screen(RenderData *rd, NodeKeyingScreenData *keyingscreen_data, MovieClip *clip, CompBuf *screenbuf) +{ + MovieClipUser user = {0}; + MovieTracking *tracking = &clip->tracking; + MovieTrackingTrack *track; + VoronoiTriangulationPoint *triangulated_points; + VoronoiSite *sites; + ImBuf *ibuf; + ListBase *tracksbase; + ListBase edges = {NULL, NULL}; + int sites_total, triangulated_points_total, triangles_total; + int (*triangles)[3]; + int i, x, y; + float *rect = screenbuf->rect; + + if (keyingscreen_data->tracking_object[0]) { + MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, keyingscreen_data->tracking_object); + + if (!object) + return; + + tracksbase = BKE_tracking_object_get_tracks(tracking, object); + } + else + tracksbase = BKE_tracking_get_active_tracks(tracking); + + sites_total = BLI_countlist(tracksbase); + + if (!sites_total) + return; + + BKE_movieclip_user_set_frame(&user, rd->cfra); + ibuf = BKE_movieclip_get_ibuf(clip, &user); + + sites = MEM_callocN(sizeof(VoronoiSite) * sites_total, "keyingscreen voronoi sites"); + track = tracksbase->first; + i = 0; + while (track) { + VoronoiSite *site = &sites[i]; + MovieTrackingMarker *marker = BKE_tracking_marker_get(track, rd->cfra); + ImBuf *pattern_ibuf = BKE_tracking_get_pattern_imbuf(ibuf, track, marker, TRUE, FALSE); + int j; + + zero_v3(site->color); + for (j = 0; j < pattern_ibuf->x * pattern_ibuf->y; j++) { + if (pattern_ibuf->rect_float) { + add_v3_v3(site->color, &pattern_ibuf->rect_float[4 * j]); + } + else { + unsigned char *rrgb = (unsigned char *)pattern_ibuf->rect; + + site->color[0] += srgb_to_linearrgb((float)rrgb[4 * j + 0] / 255.0f); + site->color[1] += srgb_to_linearrgb((float)rrgb[4 * j + 1] / 255.0f); + site->color[2] += srgb_to_linearrgb((float)rrgb[4 * j + 2] / 255.0f); + } + } + + mul_v3_fl(site->color, 1.0f / (pattern_ibuf->x * pattern_ibuf->y)); + IMB_freeImBuf(pattern_ibuf); + + site->co[0] = marker->pos[0] * screenbuf->x; + site->co[1] = marker->pos[1] * screenbuf->y; + + track = track->next; + i++; + } + + IMB_freeImBuf(ibuf); + + BLI_voronoi_compute(sites, sites_total, screenbuf->x, screenbuf->y, &edges); + + BLI_voronoi_triangulate(sites, sites_total, &edges, screenbuf->x, screenbuf->y, + &triangulated_points, &triangulated_points_total, + &triangles, &triangles_total); + + for (y = 0; y < screenbuf->y; y++) { + for (x = 0; x < screenbuf->x; x++) { + int index = 4 * (y * screenbuf->x + x); + + rect[index + 0] = rect[index + 1] = rect[index + 2] = 0.0f; + rect[index + 3] = 1.0f; + + for (i = 0; i < triangles_total; i++) { + int *triangle = triangles[i]; + VoronoiTriangulationPoint *a = &triangulated_points[triangle[0]], + *b = &triangulated_points[triangle[1]], + *c = &triangulated_points[triangle[2]]; + float co[2] = {x, y}, w[3]; + + if (barycentric_coords_v2(a->co, b->co, c->co, co, w)) { + if (barycentric_inside_triangle_v2(w)) { + rect[index + 0] += a->color[0] * w[0] + b->color[0] * w[1] + c->color[0] * w[2]; + rect[index + 1] += a->color[1] * w[0] + b->color[1] * w[1] + c->color[1] * w[2]; + rect[index + 2] += a->color[2] * w[0] + b->color[2] * w[1] + c->color[2] * w[2]; + } + } + } + } + } + + MEM_freeN(triangulated_points); + MEM_freeN(triangles); + MEM_freeN(sites); + BLI_freelistN(&edges); +} + +static void exec(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) +{ + NodeKeyingScreenData *keyingscreen_data = node->storage; + RenderData *rd = data; + CompBuf *screenbuf = NULL; + + if (node->id) { + MovieClip *clip = (MovieClip *) node->id; + MovieClipUser user = {0}; + int width, height; + + BKE_movieclip_user_set_frame(&user, rd->cfra); + BKE_movieclip_get_size(clip, &user, &width, &height); + + screenbuf = alloc_compbuf(width, height, CB_RGBA, TRUE); + compute_gradient_screen(rd, keyingscreen_data, clip, screenbuf); + } + + out[0]->data = screenbuf; +} + +static void node_composit_init_keyingscreen(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +{ + NodeKeyingScreenData *data; + + data = MEM_callocN(sizeof(NodeKeyingScreenData), "node keyingscreen data"); + + node->storage = data; +} + +void register_node_type_cmp_keyingscreen(bNodeTreeType *ttype) +{ + static bNodeType ntype; + + node_type_base(ttype, &ntype, CMP_NODE_KEYINGSCREEN, "Keying Screen", NODE_CLASS_MATTE, NODE_OPTIONS); + node_type_socket_templates(&ntype, NULL, cmp_node_keyingscreen_out); + node_type_size(&ntype, 140, 100, 320); + node_type_init(&ntype, node_composit_init_keyingscreen); + node_type_storage(&ntype, "NodeKeyingScreenData", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, exec); + + nodeRegisterType(ttype, &ntype); +} diff --git a/source/blender/nodes/composite/nodes/node_composite_mask.c b/source/blender/nodes/composite/nodes/node_composite_mask.c index 01461aec08d..d323839e690 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mask.c +++ b/source/blender/nodes/composite/nodes/node_composite_mask.c @@ -38,19 +38,16 @@ #include "node_composite_util.h" -/* **************** Translate ******************** */ +#include "../../../../intern/raskter/raskter.h" -static bNodeSocketTemplate cmp_node_mask_in[] = { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; +/* **************** Translate ******************** */ static bNodeSocketTemplate cmp_node_mask_out[] = { - { SOCK_RGBA, 0, "Image"}, + { SOCK_FLOAT, 0, "Mask"}, { -1, 0, "" } }; -static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +static void exec(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) { if (node->id) { Mask *mask = (Mask *)node->id; @@ -66,23 +63,18 @@ static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) return; } - if (in[0]->hasinput && in[0]->data) { - CompBuf *cbuf = typecheck_compbuf(in[0]->data, CB_RGBA); - - sx = cbuf->x; - sy = cbuf->y; - } - else { - sx = (rd->size * rd->xsch) / 100; - sy = (rd->size * rd->ysch) / 100; - } + sx = (rd->size * rd->xsch) / 100; + sy = (rd->size * rd->ysch) / 100; /* allocate the output buffer */ stackbuf = alloc_compbuf(sx, sy, CB_VAL, TRUE); res = stackbuf->rect; - BKE_mask_rasterize(mask, sx, sy, res, TRUE, TRUE); + BKE_mask_rasterize(mask, sx, sy, res, TRUE, node->custom1); + if(node->custom1){ + PLX_antialias_buffer(res,sx,sy); + } /* pass on output and free */ out[0]->data = stackbuf; } @@ -93,7 +85,7 @@ void register_node_type_cmp_mask(bNodeTreeType *ttype) static bNodeType ntype; node_type_base(ttype, &ntype, CMP_NODE_MASK, "Mask", NODE_CLASS_INPUT, NODE_OPTIONS); - node_type_socket_templates(&ntype, cmp_node_mask_in, cmp_node_mask_out); + node_type_socket_templates(&ntype, NULL, cmp_node_mask_out); node_type_size(&ntype, 140, 100, 320); node_type_exec(&ntype, exec); diff --git a/source/blender/nodes/composite/nodes/node_composite_movieclip.c b/source/blender/nodes/composite/nodes/node_composite_movieclip.c index 9f5a7e67c96..e8f09ae08d7 100644 --- a/source/blender/nodes/composite/nodes/node_composite_movieclip.c +++ b/source/blender/nodes/composite/nodes/node_composite_movieclip.c @@ -120,8 +120,9 @@ static void node_composit_exec_movieclip(void *data, bNode *node, bNodeStack **U if (stab->flag & TRACKING_2D_STABILIZATION) { float loc[2], scale, angle; + int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, rd->cfra); - BKE_tracking_stabilization_data(&clip->tracking, rd->cfra, stackbuf->x, stackbuf->y, + BKE_tracking_stabilization_data_get(&clip->tracking, clip_framenr, stackbuf->x, stackbuf->y, loc, &scale, &angle); out[1]->vec[0] = loc[0]; diff --git a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c index 5def9c41e19..65fe3b251d0 100644 --- a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c +++ b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c @@ -73,7 +73,7 @@ static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) BKE_movieclip_get_size(clip, &user, &width, &height); if (!node->storage) - node->storage = BKE_tracking_distortion_create(); + node->storage = BKE_tracking_distortion_new(); if (node->custom1 == 0) obuf = BKE_tracking_distortion_exec(node->storage, tracking, ibuf, width, height, overscan, 1); @@ -116,7 +116,7 @@ static const char *label(bNode *node) static void storage_free(bNode *node) { if (node->storage) - BKE_tracking_distortion_destroy(node->storage); + BKE_tracking_distortion_free(node->storage); node->storage = NULL; } diff --git a/source/blender/nodes/composite/nodes/node_composite_scale.c b/source/blender/nodes/composite/nodes/node_composite_scale.c index a36919ba553..1df67724762 100644 --- a/source/blender/nodes/composite/nodes/node_composite_scale.c +++ b/source/blender/nodes/composite/nodes/node_composite_scale.c @@ -4,7 +4,7 @@ * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -34,82 +34,134 @@ /* **************** Scale ******************** */ -static bNodeSocketTemplate cmp_node_scale_in[]= { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("X"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Y"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_FACTOR}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_scale_in[] = { + { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("X"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_FACTOR}, + { SOCK_FLOAT, 1, N_("Y"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_FACTOR}, + { -1, 0, "" } }; -static bNodeSocketTemplate cmp_node_scale_out[]= { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_scale_out[] = { + { SOCK_RGBA, 0, N_("Image")}, + { -1, 0, "" } }; /* only supports RGBA nodes now */ /* node->custom1 stores if input values are absolute or relative scale */ static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - if (out[0]->hasoutput==0) + if (out[0]->hasoutput == 0) return; - + if (in[0]->data) { - RenderData *rd= data; - CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); + RenderData *rd = data; + CompBuf *stackbuf, *cbuf = typecheck_compbuf(in[0]->data, CB_RGBA); ImBuf *ibuf; int newx, newy; - - if (node->custom1==CMP_SCALE_RELATIVE) { - newx= MAX2((int)(in[1]->vec[0]*cbuf->x), 1); - newy= MAX2((int)(in[2]->vec[0]*cbuf->y), 1); + float ofsx = 0.0f, ofsy = 0.0f; + + if (node->custom1 == CMP_SCALE_RELATIVE) { + newx = MAX2((int)(in[1]->vec[0] * cbuf->x), 1); + newy = MAX2((int)(in[2]->vec[0] * cbuf->y), 1); } - else if (node->custom1==CMP_SCALE_SCENEPERCENT) { + else if (node->custom1 == CMP_SCALE_SCENEPERCENT) { newx = cbuf->x * (rd->size / 100.0f); newy = cbuf->y * (rd->size / 100.0f); } - else if (node->custom1==CMP_SCALE_RENDERPERCENT) { - newx= (rd->xsch * rd->size)/100; - newy= (rd->ysch * rd->size)/100; + else if (node->custom1 == CMP_SCALE_RENDERPERCENT) { + + if (node->custom3 != 0.0f || node->custom4 != 0.0f) { + const float w_dst = (rd->xsch * rd->size) / 100; + const float h_dst = (rd->ysch * rd->size) / 100; + + if (w_dst > h_dst) { + ofsx = node->custom3 * w_dst; + ofsy = node->custom4 * w_dst; + } + else { + ofsx = node->custom3 * h_dst; + ofsy = node->custom4 * h_dst; + } + } + + /* supports framing options */ + if (node->custom2 & CMP_SCALE_RENDERSIZE_FRAME_ASPECT) { + /* apply aspect from clip */ + const float w_src = cbuf->x; + const float h_src = cbuf->y; + + /* destination aspect is already applied from the camera frame */ + const float w_dst = (rd->xsch * rd->size) / 100; + const float h_dst = (rd->ysch * rd->size) / 100; + + const float asp_src = w_src / h_src; + const float asp_dst = w_dst / h_dst; + + if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) { + if ((asp_src > asp_dst) == ((node->custom2 & CMP_SCALE_RENDERSIZE_FRAME_CROP) != 0)) { + /* fit X */ + const float div = asp_src / asp_dst; + newx = w_dst * div; + newy = h_dst; + } + else { + /* fit Y */ + const float div = asp_dst / asp_src; + newx = w_dst; + newy = h_dst * div; + } + } + else { + /* same as below - no aspect correction needed */ + newx = w_dst; + newy = h_dst; + } + } + else { + /* stretch */ + newx = (rd->xsch * rd->size) / 100; + newy = (rd->ysch * rd->size) / 100; + } } - else { /* CMP_SCALE_ABSOLUTE */ - newx= MAX2((int)in[1]->vec[0], 1); - newy= MAX2((int)in[2]->vec[0], 1); + else { /* CMP_SCALE_ABSOLUTE */ + newx = MAX2((int)in[1]->vec[0], 1); + newy = MAX2((int)in[2]->vec[0], 1); } - newx= MIN2(newx, CMP_SCALE_MAX); - newy= MIN2(newy, CMP_SCALE_MAX); + newx = MIN2(newx, CMP_SCALE_MAX); + newy = MIN2(newy, CMP_SCALE_MAX); - ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0); + ibuf = IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0); if (ibuf) { - ibuf->rect_float= cbuf->rect; + ibuf->rect_float = cbuf->rect; IMB_scaleImBuf(ibuf, newx, newy); - + if (ibuf->rect_float == cbuf->rect) { /* no scaling happened. */ - stackbuf= pass_on_compbuf(in[0]->data); + stackbuf = pass_on_compbuf(in[0]->data); } else { - stackbuf= alloc_compbuf(newx, newy, CB_RGBA, 0); - stackbuf->rect= ibuf->rect_float; - stackbuf->malloc= 1; + stackbuf = alloc_compbuf(newx, newy, CB_RGBA, 0); + stackbuf->rect = ibuf->rect_float; + stackbuf->malloc = 1; } - ibuf->rect_float= NULL; + ibuf->rect_float = NULL; ibuf->mall &= ~IB_rectfloat; IMB_freeImBuf(ibuf); - + /* also do the translation vector */ - stackbuf->xof = (int)(((float)newx/(float)cbuf->x) * (float)cbuf->xof); - stackbuf->yof = (int)(((float)newy/(float)cbuf->y) * (float)cbuf->yof); + stackbuf->xof = (int)(ofsx + (((float)newx / (float)cbuf->x) * (float)cbuf->xof)); + stackbuf->yof = (int)(ofsy + (((float)newy / (float)cbuf->y) * (float)cbuf->yof)); } else { - stackbuf= dupalloc_compbuf(cbuf); + stackbuf = dupalloc_compbuf(cbuf); printf("Scaling to %dx%d failed\n", newx, newy); } - - out[0]->data= stackbuf; - if (cbuf!=in[0]->data) + + out[0]->data = stackbuf; + if (cbuf != in[0]->data) free_compbuf(cbuf); } - else if (node->custom1==CMP_SCALE_ABSOLUTE) { + else if (node->custom1 == CMP_SCALE_ABSOLUTE) { CompBuf *stackbuf; int a, x, y; float *fp; @@ -126,7 +178,7 @@ static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, b fp += 4; } - out[0]->data= stackbuf; + out[0]->data = stackbuf; } } diff --git a/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c b/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c index 9ed04ab165c..fabdf8c0536 100644 --- a/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c +++ b/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c @@ -53,8 +53,9 @@ static void node_composit_exec_stabilize2d(void *data, bNode *node, bNodeStack * CompBuf *cbuf = typecheck_compbuf(in[0]->data, CB_RGBA); CompBuf *stackbuf; float loc[2], scale, angle; + int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, rd->cfra); - BKE_tracking_stabilization_data(&clip->tracking, rd->cfra, cbuf->x, cbuf->y, loc, &scale, &angle); + BKE_tracking_stabilization_data_get(&clip->tracking, clip_framenr, cbuf->x, cbuf->y, loc, &scale, &angle); stackbuf = node_composit_transform(cbuf, loc[0], loc[1], angle, scale, node->custom1); diff --git a/source/blender/nodes/composite/nodes/node_composite_tonemap.c b/source/blender/nodes/composite/nodes/node_composite_tonemap.c index a9d071ececc..50006e599e5 100644 --- a/source/blender/nodes/composite/nodes/node_composite_tonemap.c +++ b/source/blender/nodes/composite/nodes/node_composite_tonemap.c @@ -51,16 +51,16 @@ static float avgLogLum(CompBuf *src, float* auto_key, float* Lav, float* Cav) const float sc = 1.f/(src->x*src->y); *Lav = 0.f; while (p--) { - float L = 0.212671f*bc[0][0] + 0.71516f*bc[0][1] + 0.072169f*bc[0][2]; + float L = rgb_to_luma_y(bc[0]); *Lav += L; - fRGB_add(Cav, bc[0]); + add_v3_v3(Cav, bc[0]); lsum += (float)log((double)MAX2(L, 0.0) + 1e-5); maxl = (L > maxl) ? L : maxl; minl = (L < minl) ? L : minl; bc++; } *Lav *= sc; - fRGB_mult(Cav, sc); + mul_v3_fl(Cav, sc); maxl = log((double)maxl + 1e-5); minl = log((double)minl + 1e-5f); avl = lsum*sc; *auto_key = (maxl > minl) ? ((maxl - avl) / (maxl - minl)) : 1.f; return exp((double)avl); @@ -86,7 +86,7 @@ static void tonemap(NodeTonemap* ntm, CompBuf* dst, CompBuf* src) fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type]; fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type]; for (x=0; x<src->x; ++x) { - const float L = 0.212671f*sp[x][0] + 0.71516f*sp[x][1] + 0.072169f*sp[x][2]; + const float L = rgb_to_luma_y(sp[x]); float I_l = sp[x][0] + ic*(L - sp[x][0]); float I_g = Cav[0] + ic*(Lav - Cav[0]); float I_a = I_l + ia*(I_g - I_l); @@ -109,8 +109,8 @@ static void tonemap(NodeTonemap* ntm, CompBuf* dst, CompBuf* src) fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type]; fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type]; for (x=0; x<src->x; x++) { - fRGB_copy(dp[x], sp[x]); - fRGB_mult(dp[x], al); + copy_v4_v4(dp[x], sp[x]); + mul_v3_fl(dp[x], al); dr = dp[x][0] + ntm->offset; dg = dp[x][1] + ntm->offset; db = dp[x][2] + ntm->offset; diff --git a/source/blender/nodes/composite/nodes/node_composite_vecBlur.c b/source/blender/nodes/composite/nodes/node_composite_vecBlur.c index fd2cc724b82..e1a20a65227 100644 --- a/source/blender/nodes/composite/nodes/node_composite_vecBlur.c +++ b/source/blender/nodes/composite/nodes/node_composite_vecBlur.c @@ -34,63 +34,63 @@ /* **************** VECTOR BLUR ******************** */ -static bNodeSocketTemplate cmp_node_vecblur_in[]= { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Z"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_VECTOR, 1, N_("Speed"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_VELOCITY}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_vecblur_in[] = { + { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("Z"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + { SOCK_VECTOR, 1, N_("Speed"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_VELOCITY}, + { -1, 0, "" } }; -static bNodeSocketTemplate cmp_node_vecblur_out[]= { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_vecblur_out[] = { + { SOCK_RGBA, 0, N_("Image")}, + { -1, 0, "" } }; static void node_composit_exec_vecblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { - NodeBlurData *nbd= node->storage; - CompBuf *new, *img= in[0]->data, *vecbuf= in[2]->data, *zbuf= in[1]->data; + NodeBlurData *nbd = node->storage; + CompBuf *new, *img = in[0]->data, *vecbuf = in[2]->data, *zbuf = in[1]->data; - if (img==NULL || vecbuf==NULL || zbuf==NULL || out[0]->hasoutput==0) + if (img == NULL || vecbuf == NULL || zbuf == NULL || out[0]->hasoutput == 0) return; - if (vecbuf->x!=img->x || vecbuf->y!=img->y) { + if (vecbuf->x != img->x || vecbuf->y != img->y) { printf("ERROR: cannot do different sized vecbuf yet\n"); return; } - if (vecbuf->type!=CB_VEC4) { + if (vecbuf->type != CB_VEC4) { printf("ERROR: input should be vecbuf\n"); return; } - if (zbuf->type!=CB_VAL) { + if (zbuf->type != CB_VAL) { printf("ERROR: input should be zbuf\n"); return; } - if (zbuf->x!=img->x || zbuf->y!=img->y) { + if (zbuf->x != img->x || zbuf->y != img->y) { printf("ERROR: cannot do different sized zbuf yet\n"); return; } /* allow the input image to be of another type */ - img= typecheck_compbuf(in[0]->data, CB_RGBA); + img = typecheck_compbuf(in[0]->data, CB_RGBA); - new= dupalloc_compbuf(img); + new = dupalloc_compbuf(img); /* call special zbuffer version */ RE_zbuf_accumulate_vecblur(nbd, img->x, img->y, new->rect, img->rect, vecbuf->rect, zbuf->rect); - out[0]->data= new; + out[0]->data = new; - if (img!=in[0]->data) + if (img != in[0]->data) free_compbuf(img); } -static void node_composit_init_vecblur(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +static void node_composit_init_vecblur(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp)) { - NodeBlurData *nbd= MEM_callocN(sizeof(NodeBlurData), "node blur data"); - node->storage= nbd; - nbd->samples= 32; - nbd->fac= 1.0f; + NodeBlurData *nbd = MEM_callocN(sizeof(NodeBlurData), "node blur data"); + node->storage = nbd; + nbd->samples = 32; + nbd->fac = 1.0f; } /* custom1: itterations, custom2: maxspeed (0 = nolimit) */ diff --git a/source/blender/nodes/composite/nodes/node_composite_viewer.c b/source/blender/nodes/composite/nodes/node_composite_viewer.c index 1fc9399e876..e97863a9463 100644 --- a/source/blender/nodes/composite/nodes/node_composite_viewer.c +++ b/source/blender/nodes/composite/nodes/node_composite_viewer.c @@ -34,11 +34,11 @@ /* **************** VIEWER ******************** */ -static bNodeSocketTemplate cmp_node_viewer_in[]= { - { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Z"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" } +static bNodeSocketTemplate cmp_node_viewer_in[] = { + { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + { SOCK_FLOAT, 1, N_("Z"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + { -1, 0, "" } }; @@ -47,9 +47,9 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, /* 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; + 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; @@ -58,8 +58,8 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, 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) { + 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; @@ -71,28 +71,28 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, 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; + 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; + rectx = tbuf->x; + recty = tbuf->y; } /* make ibuf, and connect to ima */ - ibuf->x= rectx; - ibuf->y= recty; + ibuf->x = rectx; + ibuf->y = recty; imb_addrectfloatImBuf(ibuf); - ima->ok= IMA_OK_LOADED; + 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; + 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) { + if (in[1]->data == NULL) { composit1_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA); } else @@ -100,14 +100,14 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, /* zbuf option */ if (in[2]->data) { - CompBuf *zbuf= alloc_compbuf(rectx, recty, CB_VAL, 1); - ibuf->zbuf_float= zbuf->rect; + 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; + zbuf->malloc = 0; free_compbuf(zbuf); } @@ -122,13 +122,13 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, } } -static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp)) { - ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user"); - node->storage= iuser; - iuser->sfra= 1; - iuser->fie_ima= 2; - iuser->ok= 1; + ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); + node->storage = iuser; + iuser->sfra = 1; + iuser->fie_ima = 2; + iuser->ok = 1; node->custom3 = 0.5f; node->custom4 = 0.5f; } diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index 3d1b656fc4e..150bede4b7c 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -32,8 +32,6 @@ #include <string.h> -#include "DNA_action_types.h" -#include "DNA_anim_types.h" #include "DNA_node_types.h" #include "BLI_listbase.h" @@ -42,8 +40,6 @@ #include "BLF_translation.h" -#include "BKE_action.h" -#include "BKE_animsys.h" #include "BKE_global.h" #include "BKE_library.h" #include "BKE_main.h" @@ -112,294 +108,6 @@ bNodeSocket *node_group_add_extern_socket(bNodeTree *UNUSED(ntree), ListBase *lb return sock; } -bNode *node_group_make_from_selected(bNodeTree *ntree) -{ - bNodeLink *link, *linkn; - bNode *node, *gnode, *nextn; - bNodeTree *ngroup; - bNodeSocket *gsock; - ListBase anim_basepaths = {NULL, NULL}; - float min[2], max[2]; - int totnode=0; - bNodeTemplate ntemp; - - INIT_MINMAX2(min, max); - - /* is there something to group? also do some clearing */ - for (node= ntree->nodes.first; node; node= node->next) { - if (node->flag & NODE_SELECT) { - /* no groups in groups */ - if (node->type==NODE_GROUP) - return NULL; - DO_MINMAX2((&node->locx), min, max); - totnode++; - } - node->done = FALSE; - } - if (totnode==0) return NULL; - - /* check if all connections are OK, no unselected node has both - * inputs and outputs to a selection */ - for (link= ntree->links.first; link; link= link->next) { - if (link->fromnode && link->tonode && link->fromnode->flag & NODE_SELECT) - link->tonode->done |= 1; - if (link->fromnode && link->tonode && link->tonode->flag & NODE_SELECT) - link->fromnode->done |= 2; - } - - for (node= ntree->nodes.first; node; node= node->next) { - if ((node->flag & NODE_SELECT)==0) - if (node->done==3) - break; - } - if (node) - return NULL; - - /* OK! new nodetree */ - ngroup= ntreeAddTree("NodeGroup", ntree->type, NODE_GROUP); - - /* move nodes over */ - for (node= ntree->nodes.first; node; node= nextn) { - nextn= node->next; - if (node->flag & NODE_SELECT) { - /* keep track of this node's RNA "base" path (the part of the pat identifying the node) - * if the old nodetree has animation data which potentially covers this node - */ - if (ntree->adt) { - PointerRNA ptr; - char *path; - - RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); - path = RNA_path_from_ID_to_struct(&ptr); - - if (path) - BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); - } - - /* change node-collection membership */ - BLI_remlink(&ntree->nodes, node); - BLI_addtail(&ngroup->nodes, node); - - node->locx-= 0.5f*(min[0]+max[0]); - node->locy-= 0.5f*(min[1]+max[1]); - } - } - - /* move animation data over */ - if (ntree->adt) { - LinkData *ld, *ldn=NULL; - - BKE_animdata_separate_by_basepath(&ntree->id, &ngroup->id, &anim_basepaths); - - /* paths + their wrappers need to be freed */ - for (ld = anim_basepaths.first; ld; ld = ldn) { - ldn = ld->next; - - MEM_freeN(ld->data); - BLI_freelinkN(&anim_basepaths, ld); - } - } - - /* node groups don't use internal cached data */ - ntreeFreeCache(ngroup); - - /* make group node */ - ntemp.type = NODE_GROUP; - ntemp.ngroup = ngroup; - gnode= nodeAddNode(ntree, &ntemp); - gnode->locx= 0.5f*(min[0]+max[0]); - gnode->locy= 0.5f*(min[1]+max[1]); - - /* relink external sockets */ - for (link= ntree->links.first; link; link= linkn) { - linkn= link->next; - - if (link->fromnode && link->tonode && (link->fromnode->flag & link->tonode->flag & NODE_SELECT)) { - BLI_remlink(&ntree->links, link); - BLI_addtail(&ngroup->links, link); - } - else if (link->tonode && (link->tonode->flag & NODE_SELECT)) { - gsock = node_group_expose_socket(ngroup, link->tosock, SOCK_IN); - link->tosock->link = nodeAddLink(ngroup, NULL, gsock, link->tonode, link->tosock); - link->tosock = node_group_add_extern_socket(ntree, &gnode->inputs, SOCK_IN, gsock); - link->tonode = gnode; - } - else if (link->fromnode && (link->fromnode->flag & NODE_SELECT)) { - /* search for existing group node socket */ - for (gsock=ngroup->outputs.first; gsock; gsock=gsock->next) - if (gsock->link && gsock->link->fromsock==link->fromsock) - break; - if (!gsock) { - gsock = node_group_expose_socket(ngroup, link->fromsock, SOCK_OUT); - gsock->link = nodeAddLink(ngroup, link->fromnode, link->fromsock, NULL, gsock); - link->fromsock = node_group_add_extern_socket(ntree, &gnode->outputs, SOCK_OUT, gsock); - } - else - link->fromsock = node_group_find_output(gnode, gsock); - link->fromnode = gnode; - } - } - - /* update of the group tree */ - ngroup->update |= NTREE_UPDATE; - ntreeUpdateTree(ngroup); - /* update of the tree containing the group instance node */ - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - ntreeUpdateTree(ntree); - - return gnode; -} - -/* returns 1 if its OK */ -int node_group_ungroup(bNodeTree *ntree, bNode *gnode) -{ - bNodeLink *link, *linkn; - bNode *node, *nextn; - bNodeTree *ngroup, *wgroup; - ListBase anim_basepaths = {NULL, NULL}; - - ngroup= (bNodeTree *)gnode->id; - if (ngroup==NULL) return 0; - - /* clear new pointers, set in copytree */ - for (node= ntree->nodes.first; node; node= node->next) - node->new_node= NULL; - - /* wgroup is a temporary copy of the NodeTree we're merging in - * - all of wgroup's nodes are transferred across to their new home - * - ngroup (i.e. the source NodeTree) is left unscathed - */ - wgroup= ntreeCopyTree(ngroup); - - /* add the nodes into the ntree */ - for (node= wgroup->nodes.first; node; node= nextn) { - nextn= node->next; - - /* keep track of this node's RNA "base" path (the part of the pat identifying the node) - * if the old nodetree has animation data which potentially covers this node - */ - if (wgroup->adt) { - PointerRNA ptr; - char *path; - - RNA_pointer_create(&wgroup->id, &RNA_Node, node, &ptr); - path = RNA_path_from_ID_to_struct(&ptr); - - if (path) - BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); - } - - /* migrate node */ - BLI_remlink(&wgroup->nodes, node); - BLI_addtail(&ntree->nodes, node); - - node->locx += gnode->locx; - node->locy += gnode->locy; - - node->flag |= NODE_SELECT; - } - - /* restore external links to and from the gnode */ - for (link= ntree->links.first; link; link= link->next) { - if (link->fromnode==gnode) { - if (link->fromsock->groupsock) { - bNodeSocket *gsock= link->fromsock->groupsock; - if (gsock->link) { - if (gsock->link->fromnode) { - /* NB: using the new internal copies here! the groupsock pointer still maps to the old tree */ - link->fromnode = (gsock->link->fromnode ? gsock->link->fromnode->new_node : NULL); - link->fromsock = gsock->link->fromsock->new_sock; - } - else { - /* group output directly maps to group input */ - bNodeSocket *insock= node_group_find_input(gnode, gsock->link->fromsock); - if (insock->link) { - link->fromnode = insock->link->fromnode; - link->fromsock = insock->link->fromsock; - } - } - } - else { - /* copy the default input value from the group socket default to the external socket */ - node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, gsock->type, gsock->default_value); - } - } - } - } - /* remove internal output links, these are not used anymore */ - for (link=wgroup->links.first; link; link= linkn) { - linkn = link->next; - if (!link->tonode) - nodeRemLink(wgroup, link); - } - /* restore links from internal nodes */ - for (link= wgroup->links.first; link; link= link->next) { - /* indicates link to group input */ - if (!link->fromnode) { - /* NB: can't use find_group_node_input here, - * because gnode sockets still point to the old tree! - */ - bNodeSocket *insock; - for (insock= gnode->inputs.first; insock; insock= insock->next) - if (insock->groupsock->new_sock == link->fromsock) - break; - if (insock->link) { - link->fromnode = insock->link->fromnode; - link->fromsock = insock->link->fromsock; - } - else { - /* copy the default input value from the group node socket default to the internal socket */ - node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, insock->type, insock->default_value); - nodeRemLink(wgroup, link); - } - } - } - - /* add internal links to the ntree */ - for (link= wgroup->links.first; link; link= linkn) { - linkn= link->next; - BLI_remlink(&wgroup->links, link); - BLI_addtail(&ntree->links, link); - } - - /* and copy across the animation, - * note that the animation data's action can be NULL here */ - if (wgroup->adt) { - LinkData *ld, *ldn=NULL; - bAction *waction; - - /* firstly, wgroup needs to temporary dummy action that can be destroyed, as it shares copies */ - waction = wgroup->adt->action = BKE_action_copy(wgroup->adt->action); - - /* now perform the moving */ - BKE_animdata_separate_by_basepath(&wgroup->id, &ntree->id, &anim_basepaths); - - /* paths + their wrappers need to be freed */ - for (ld = anim_basepaths.first; ld; ld = ldn) { - ldn = ld->next; - - MEM_freeN(ld->data); - BLI_freelinkN(&anim_basepaths, ld); - } - - /* free temp action too */ - if (waction) { - BKE_libblock_free(&G.main->action, waction); - } - } - - /* delete the group instance. this also removes old input links! */ - nodeFreeNode(ntree, gnode); - - /* free the group tree (takes care of user count) */ - BKE_libblock_free(&G.main->nodetree, wgroup); - - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - ntreeUpdateTree(ntree); - - return 1; -} - bNodeSocket *node_group_add_socket(bNodeTree *ngroup, const char *name, int type, int in_out) { bNodeSocketType *stype = ntreeGetSocketType(type); @@ -849,7 +557,7 @@ static bNodeSocketTemplate node_reroute_out[]= { }; /* simple, only a single input and output here */ -ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node) +static ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node) { bNodeLink *link; ListBase ret; @@ -872,6 +580,23 @@ ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node) return ret; } +static void node_reroute_update(bNodeTree *UNUSED(ntree), bNode *node) +{ + bNodeSocket *input = node->inputs.first; + bNodeSocket *output = node->outputs.first; + int type = SOCK_FLOAT; + + /* determine socket type from unambiguous input/output connection if possible */ + if (input->limit==1 && input->link) + type = input->link->fromsock->type; + else if (output->limit==1 && output->link) + type = output->link->tosock->type; + + /* same type for input/output */ + nodeSocketSetType(input, type); + nodeSocketSetType(output, type); +} + void register_node_type_reroute(bNodeTreeType *ttype) { /* frame type is used for all tree types, needs dynamic allocation */ @@ -880,6 +605,7 @@ void register_node_type_reroute(bNodeTreeType *ttype) node_type_base(ttype, ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0); node_type_socket_templates(ntype, node_reroute_in, node_reroute_out); node_type_internal_connect(ntype, node_reroute_internal_connect); + node_type_update(ntype, node_reroute_update, NULL); ntype->needs_free = 1; nodeRegisterType(ttype, ntype); diff --git a/source/blender/nodes/intern/node_common.h b/source/blender/nodes/intern/node_common.h index 616221d6658..f1bb837e483 100644 --- a/source/blender/nodes/intern/node_common.h +++ b/source/blender/nodes/intern/node_common.h @@ -37,8 +37,6 @@ struct bNodeTree; -struct bNodeSocket *node_group_add_extern_socket(struct bNodeTree *ntree, ListBase *lb, int in_out, struct bNodeSocket *gsock); - void node_group_init(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp); void node_forloop_init(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp); void node_whileloop_init(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp); |