~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/nodes/composite/nodes/node_composite_dilate.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
/* **************** Dilate/Erode ******************** */
37
37
 
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},
40
 
        {       -1, 0, ""       }
41
 
};
42
 
static bNodeSocketTemplate cmp_node_dilateerode_out[]= {
43
 
        {       SOCK_FLOAT, 0, "Mask"},
44
 
        {       -1, 0, ""       }
45
 
};
46
 
 
47
 
static void morpho_dilate(CompBuf *cbuf)
48
 
{
49
 
        int x, y;
50
 
        float *p, *rectf = cbuf->rect;
51
 
        
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));
56
 
                }
57
 
        }
58
 
 
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));
63
 
                }
64
 
        }
65
 
 
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));
70
 
                }
71
 
        }
72
 
 
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));
77
 
                }
78
 
        }
79
 
}
80
 
 
81
 
static void morpho_erode(CompBuf *cbuf)
82
 
{
83
 
        int x, y;
84
 
        float *p, *rectf = cbuf->rect;
85
 
        
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));
90
 
                }
91
 
        }
92
 
 
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));
97
 
                }
98
 
        }
99
 
 
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));
104
 
                }
105
 
        }
106
 
 
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));
111
 
                }
112
 
        }
113
 
        
114
 
}
115
 
 
116
 
static void node_composit_exec_dilateerode(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
117
 
{
118
 
        /* stack order in: mask */
119
 
        /* stack order out: mask */
120
 
        if (out[0]->hasoutput==0) 
121
 
                return;
122
 
        
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;
127
 
        }
128
 
        else {
129
 
                /* make output size of input image */
130
 
                CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_VAL);
131
 
                CompBuf *stackbuf= dupalloc_compbuf(cbuf);
132
 
                short i;
133
 
                
134
 
                if (node->custom2 > 0) { // positive, dilate
135
 
                        for (i = 0; i < node->custom2; i++)
136
 
                                morpho_dilate(stackbuf);
137
 
                }
138
 
                else if (node->custom2 < 0) { // negative, erode
139
 
                        for (i = 0; i > node->custom2; i--)
140
 
                                morpho_erode(stackbuf);
141
 
                }
142
 
                
143
 
                if (cbuf!=in[0]->data)
144
 
                        free_compbuf(cbuf);
145
 
                
146
 
                out[0]->data= stackbuf;
147
 
        }
 
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},
 
40
        {   -1, 0, ""   }
 
41
};
 
42
static bNodeSocketTemplate cmp_node_dilateerode_out[] = {
 
43
        {   SOCK_FLOAT, 0, N_("Mask")},
 
44
        {   -1, 0, ""   }
 
45
};
 
46
 
 
47
static void node_composit_init_dilateerode(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
 
48
{
 
49
        NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), "NodeDilateErode");
 
50
        data->falloff = PROP_SMOOTH;
 
51
        node->storage = data;
148
52
}
149
53
 
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);
158
62
        
 
63
        node_type_storage(&ntype, "NodeDilateErode", node_free_standard_storage, node_copy_standard_storage);
 
64
 
159
65
        nodeRegisterType(ttype, &ntype);
160
66
}