36
36
/* **************** Dilate/Erode ******************** */
38
static bNodeSocketTemplate cmp_node_dilateerode_in[]= {
39
{ SOCK_FLOAT, 1, "Mask", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR},
42
static bNodeSocketTemplate cmp_node_dilateerode_out[]= {
43
{ SOCK_FLOAT, 0, "Mask"},
47
static void morpho_dilate(CompBuf *cbuf)
50
float *p, *rectf = cbuf->rect;
52
for (y=0; y < cbuf->y; y++) {
53
for (x=0; x < cbuf->x-1; x++) {
54
p = rectf + cbuf->x*y + x;
55
*p = MAX2(*p, *(p + 1));
59
for (y=0; y < cbuf->y; y++) {
60
for (x=cbuf->x-1; x >= 1; x--) {
61
p = rectf + cbuf->x*y + x;
62
*p = MAX2(*p, *(p - 1));
66
for (x=0; x < cbuf->x; x++) {
67
for (y=0; y < cbuf->y-1; y++) {
68
p = rectf + cbuf->x*y + x;
69
*p = MAX2(*p, *(p + cbuf->x));
73
for (x=0; x < cbuf->x; x++) {
74
for (y=cbuf->y-1; y >= 1; y--) {
75
p = rectf + cbuf->x*y + x;
76
*p = MAX2(*p, *(p - cbuf->x));
81
static void morpho_erode(CompBuf *cbuf)
84
float *p, *rectf = cbuf->rect;
86
for (y=0; y < cbuf->y; y++) {
87
for (x=0; x < cbuf->x-1; x++) {
88
p = rectf + cbuf->x*y + x;
89
*p = MIN2(*p, *(p + 1));
93
for (y=0; y < cbuf->y; y++) {
94
for (x=cbuf->x-1; x >= 1; x--) {
95
p = rectf + cbuf->x*y + x;
96
*p = MIN2(*p, *(p - 1));
100
for (x=0; x < cbuf->x; x++) {
101
for (y=0; y < cbuf->y-1; y++) {
102
p = rectf + cbuf->x*y + x;
103
*p = MIN2(*p, *(p + cbuf->x));
107
for (x=0; x < cbuf->x; x++) {
108
for (y=cbuf->y-1; y >= 1; y--) {
109
p = rectf + cbuf->x*y + x;
110
*p = MIN2(*p, *(p - cbuf->x));
116
static void node_composit_exec_dilateerode(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
118
/* stack order in: mask */
119
/* stack order out: mask */
120
if (out[0]->hasoutput==0)
123
/* input no image? then only color operation */
124
if (in[0]->data==NULL) {
125
out[0]->vec[0] = out[0]->vec[1] = out[0]->vec[2] = 0.0f;
126
out[0]->vec[3] = 0.0f;
129
/* make output size of input image */
130
CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_VAL);
131
CompBuf *stackbuf= dupalloc_compbuf(cbuf);
134
if (node->custom2 > 0) { // positive, dilate
135
for (i = 0; i < node->custom2; i++)
136
morpho_dilate(stackbuf);
138
else if (node->custom2 < 0) { // negative, erode
139
for (i = 0; i > node->custom2; i--)
140
morpho_erode(stackbuf);
143
if (cbuf!=in[0]->data)
146
out[0]->data= stackbuf;
38
static bNodeSocketTemplate cmp_node_dilateerode_in[] = {
39
{ SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR},
42
static bNodeSocketTemplate cmp_node_dilateerode_out[] = {
43
{ SOCK_FLOAT, 0, N_("Mask")},
47
static void node_composit_init_dilateerode(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
49
NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), "NodeDilateErode");
50
data->falloff = PROP_SMOOTH;
150
54
void register_node_type_cmp_dilateerode(bNodeTreeType *ttype)
154
58
node_type_base(ttype, &ntype, CMP_NODE_DILATEERODE, "Dilate/Erode", NODE_CLASS_OP_FILTER, NODE_OPTIONS);
155
59
node_type_socket_templates(&ntype, cmp_node_dilateerode_in, cmp_node_dilateerode_out);
156
60
node_type_size(&ntype, 130, 100, 320);
157
node_type_exec(&ntype, node_composit_exec_dilateerode);
61
node_type_init(&ntype, node_composit_init_dilateerode);
63
node_type_storage(&ntype, "NodeDilateErode", node_free_standard_storage, node_copy_standard_storage);
159
65
nodeRegisterType(ttype, &ntype);