Index: source/blender/blenkernel/BKE_node.h =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/BKE_node.h,v retrieving revision 1.15 diff -u -r1.15 BKE_node.h --- source/blender/blenkernel/BKE_node.h 3 Jul 2006 09:49:12 -0000 1.15 +++ source/blender/blenkernel/BKE_node.h 19 Jul 2006 01:28:17 -0000 @@ -224,6 +225,8 @@ #define CMP_NODE_TEXTURE 224 #define CMP_NODE_TRANSLATE 225 #define CMP_NODE_ZCOMBINE 226 +#define CMP_NODE_COMBRGBA 227 +#define CMP_NODE_DILATEERODE 228 /* filter types */ Index: source/blender/blenkernel/intern/node_composite.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/intern/node_composite.c,v retrieving revision 1.51 diff -u -r1.51 node_composite.c --- source/blender/blenkernel/intern/node_composite.c 3 Jul 2006 15:25:11 -0000 1.51 +++ source/blender/blenkernel/intern/node_composite.c 19 Jul 2006 01:28:22 -0000 @@ -1393,7 +1393,7 @@ { NodeHueSat *nhs= node->storage; - if(*fac!=0.0f && (nhs->hue!=0.5f || nhs->sat!=1.0)) { + if(*fac!=0.0f && (nhs->hue!=0.5f || nhs->sat!=1.0 || nhs->val!=1.0)) { float col[3], hsv[3], mfac= 1.0f - *fac; rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2); @@ -1401,6 +1401,8 @@ if(hsv[0]>1.0) hsv[0]-=1.0; else if(hsv[0]<0.0) hsv[0]+= 1.0; hsv[1]*= nhs->sat; if(hsv[1]>1.0) hsv[1]= 1.0; else if(hsv[1]<0.0) hsv[1]= 0.0; + hsv[2]*= nhs->val; + if(hsv[2]>1.0) hsv[2]= 1.0; else if(hsv[2]<0.0) hsv[2]= 0.0; hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2); out[0]= mfac*in[0] + *fac*col[0]; @@ -1436,7 +1438,7 @@ static bNodeType cmp_node_hue_sat= { /* type code */ CMP_NODE_HUE_SAT, - /* name */ "Hue Saturation", + /* name */ "Hue Saturation Value", /* width+range */ 150, 80, 250, /* class+opts */ NODE_CLASS_OP_COLOR, NODE_OPTIONS, /* input sock */ cmp_node_hue_sat_in, @@ -1925,6 +1927,71 @@ }; +/* **************** COMBINE RGBA ******************** */ +static bNodeSocketType cmp_node_combrgba_in[]= { + { SOCK_VALUE, 1, "R", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 1, "G", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 1, "B", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 1, "A", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; +static bNodeSocketType cmp_node_combrgba_out[]= { + { SOCK_RGBA, 0, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void do_combrgba(bNode *node, float *out, float *in1, float *in2, float *in3, float *in4) +{ + out[0] = in1[0]; + out[1] = in2[0]; + out[2] = in3[0]; + out[3] = in4[0]; +} + +static void node_composit_exec_combrgba(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + /* stack order out: 1 rgba channels */ + /* stack order in: 4 value channels */ + + /* input no image? then only color operation */ + if((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) { + out[0]->vec[0] = in[0]->vec[0]; + out[0]->vec[1] = in[1]->vec[0]; + out[0]->vec[2] = in[2]->vec[0]; + out[0]->vec[3] = in[3]->vec[0]; + } + else { + /* make output size of first available input image */ + CompBuf *cbuf; + CompBuf *stackbuf; + + if (in[0]->data) cbuf = in[0]->data; + else if (in[1]->data) cbuf = in[1]->data; + else if (in[2]->data) cbuf = in[2]->data; + else if (in[3]->data) cbuf = in[3]->data; + + stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs + + composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, + in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, + do_combrgba, CB_VAL, CB_VAL, CB_VAL, CB_VAL); + + out[0]->data= stackbuf; + } +} + +static bNodeType cmp_node_combrgba= { + /* type code */ CMP_NODE_COMBRGBA, + /* name */ "Combine RGBA", + /* width+range */ 80, 40, 140, + /* class+opts */ NODE_CLASS_CONVERTOR, NODE_OPTIONS, + /* input sock */ cmp_node_combrgba_in, + /* output sock */ cmp_node_combrgba_out, + /* storage */ "", + /* execfunc */ node_composit_exec_combrgba + +}; + /* **************** SET ALPHA ******************** */ static bNodeSocketType cmp_node_setalpha_in[]= { { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, @@ -2884,6 +2951,127 @@ /* execfunc */ node_composit_exec_translate }; +/* **************** Dilate/Erode ******************** */ + +static bNodeSocketType cmp_node_dilateerode_in[]= { + { SOCK_VALUE, 1, "Mask", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; +static bNodeSocketType cmp_node_dilateerode_out[]= { + { SOCK_VALUE, 0, "Mask", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +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=cbuf->x-1; x >= 1; x--) { + p = rectf + cbuf->x*y + x; + *p = MAX2(*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=cbuf->y-1; y >= 1; y--) { + p = rectf + cbuf->x*y + x; + *p = MAX2(*p, *(p - cbuf->x)); + } + } +} + +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=cbuf->x-1; x >= 1; x--) { + p = rectf + cbuf->x*y + x; + *p = MIN2(*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=cbuf->y-1; y >= 1; y--) { + p = rectf + cbuf->x*y + x; + *p = MIN2(*p, *(p - cbuf->x)); + } + } + +} + +static void node_composit_exec_dilateerode(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + /* stack order in: mask */ + /* stack order out: mask */ + 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; + } + else { + /* make output size of input image */ + CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_VAL); + CompBuf *stackbuf= dupalloc_compbuf(cbuf); + short i; + + if (node->custom2 > 0) { // positive, dilate + for (i = 0; i < node->custom2; i++) + morpho_dilate(stackbuf); + } else if (node->custom2 < 0) { // negative, erode + for (i = 0; i > node->custom2; i--) + morpho_erode(stackbuf); + } + + out[0]->data= stackbuf; + } +} + +static bNodeType cmp_node_dilateerode= { + /* type code */ CMP_NODE_DILATEERODE, + /* name */ "Dilate/Erode", + /* width+range */ 130, 100, 320, + /* class+opts */ NODE_CLASS_OP_FILTER, NODE_OPTIONS, + /* input sock */ cmp_node_dilateerode_in, + /* output sock */ cmp_node_dilateerode_out, + /* storage */ "", + /* execfunc */ node_composit_exec_dilateerode +}; + /* ****************** types array for all shaders ****************** */ @@ -2911,10 +3099,12 @@ &cmp_node_rgbtobw, &cmp_node_seprgba, &cmp_node_sephsva, + &cmp_node_combrgba, &cmp_node_setalpha, &cmp_node_texture, &cmp_node_translate, &cmp_node_zcombine, + &cmp_node_dilateerode, NULL }; Index: source/blender/blenkernel/intern/node.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/intern/node.c,v retrieving revision 1.40 diff -u -r1.40 node.c --- source/blender/blenkernel/intern/node.c 9 Jul 2006 11:54:41 -0000 1.40 +++ source/blender/blenkernel/intern/node.c 19 Jul 2006 01:28:25 -0000 @@ -795,6 +800,7 @@ node->storage= nhs; nhs->hue= 0.5f; nhs->sat= 1.0f; + nhs->val= 1.0f; } } Index: source/blender/src/drawnode.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/src/drawnode.c,v retrieving revision 1.32 diff -u -r1.32 drawnode.c --- source/blender/src/drawnode.c 3 Jul 2006 09:49:12 -0000 1.32 +++ source/blender/src/drawnode.c 19 Jul 2006 01:28:27 -0000 @@ -975,16 +978,28 @@ NodeHueSat *nhs= node->storage; uiBlockBeginAlign(block); - uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Hue ", - butr->xmin, butr->ymin+19.0f, butr->xmax-butr->xmin, 19, + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Hue: ", + butr->xmin, butr->ymin+40.0f, butr->xmax-butr->xmin, 20, &nhs->hue, 0.0f, 1.0f, 100, 0, ""); - uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Sat ", - butr->xmin, butr->ymin, butr->xmax-butr->xmin, 19, + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Sat: ", + butr->xmin, butr->ymin+20.0f, butr->xmax-butr->xmin, 20, &nhs->sat, 0.0f, 2.0f, 100, 0, ""); + uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Val: ", + butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, + &nhs->val, 0.0f, 2.0f, 100, 0, ""); } - return 38; + return 60; } +static int node_composit_buts_dilateerode(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr) +{ + if(block) { + uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Distance:", + butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, + &node->custom2, -100, 100, 0, 0, "Distance to grow/shrink (number of iterations)"); + } + return 20; +} /* only once called */ static void node_composit_set_butfunc(bNodeType *ntype) @@ -1043,6 +1058,9 @@ break; case CMP_NODE_TEXTURE: ntype->butfunc= node_buts_texture; + break; + case CMP_NODE_DILATEERODE: + ntype->butfunc= node_composit_buts_dilateerode; break; default: ntype->butfunc= NULL; Index: source/blender/makesdna/DNA_node_types.h =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_node_types.h,v retrieving revision 1.12 diff -u -r1.12 DNA_node_types.h --- source/blender/makesdna/DNA_node_types.h 17 Jun 2006 13:04:09 -0000 1.12 +++ source/blender/makesdna/DNA_node_types.h 19 Jul 2006 01:28:27 -0000 @@ -193,7 +193,7 @@ } NodeBlurData; typedef struct NodeHueSat { - float hue, sat; + float hue, sat, val; } NodeHueSat; #endif