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

« back to all changes in this revision

Viewing changes to source/blender/nodes/composite/nodes/node_composite_normalize.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:
34
34
 
35
35
 
36
36
/* **************** NORMALIZE single channel, useful for Z buffer ******************** */
37
 
static bNodeSocketTemplate cmp_node_normalize_in[]= {
38
 
        {   SOCK_FLOAT, 1, "Value",         1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
39
 
        {   -1, 0, ""   }
40
 
};
41
 
static bNodeSocketTemplate cmp_node_normalize_out[]= {
42
 
        {   SOCK_FLOAT, 0, "Value"},
43
 
        {   -1, 0, ""   }
44
 
};
45
 
 
46
 
static void do_normalize(bNode *UNUSED(node), float *out, float *src, float *min, float *mult)
47
 
{
48
 
        float res;
49
 
        res = (src[0] - min[0]) * mult[0];
50
 
        if (res > 1.0f) {
51
 
                out[0] = 1.0f;
52
 
        }
53
 
        else if (res < 0.0f) {
54
 
                out[0] = 0.0f;
55
 
        }
56
 
        else {
57
 
                out[0] = res;
58
 
        }
59
 
}
60
 
 
61
 
/* The code below assumes all data is inside range +- this, and that input buffer is single channel */
62
 
#define BLENDER_ZMAX 10000.0f
63
 
 
64
 
static void node_composit_exec_normalize(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
65
 
{
66
 
        /* stack order in: valbuf */
67
 
        /* stack order out: valbuf */
68
 
        if (out[0]->hasoutput==0) return;
69
 
 
70
 
        /* Input has no image buffer? Then pass the value */
71
 
        if (in[0]->data==NULL) {
72
 
                copy_v4_v4(out[0]->vec, in[0]->vec);
73
 
        }
74
 
        else {
75
 
                float min = 1.0f+BLENDER_ZMAX;
76
 
                float max = -1.0f-BLENDER_ZMAX;
77
 
                float mult = 1.0f;
78
 
                float *val;
79
 
                /* make output size of input image */
80
 
                CompBuf *cbuf= in[0]->data;
81
 
                int tot= cbuf->x*cbuf->y;
82
 
                CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
83
 
 
84
 
                for (val = cbuf->rect; tot; tot--, val++) {
85
 
                        if ((*val > max) && (*val <= BLENDER_ZMAX)) {
86
 
                                max = *val;
87
 
                        }
88
 
                        if ((*val < min) && (*val >= -BLENDER_ZMAX)) {
89
 
                                min = *val;
90
 
                        }
91
 
                }
92
 
                /* In the rare case of flat buffer, which would cause a divide by 0, just pass the input to the output */
93
 
                if ((max-min) != 0.0f) {
94
 
                        mult = 1.0f/(max-min);
95
 
                        composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, NULL, &min, NULL, &mult, do_normalize, CB_VAL, CB_VAL, CB_VAL);
96
 
                }
97
 
                else {
98
 
                        memcpy(stackbuf->rect, cbuf->rect, sizeof(float) * cbuf->x * cbuf->y);
99
 
                }
100
 
 
101
 
                out[0]->data= stackbuf;
102
 
        }
103
 
}
 
37
static bNodeSocketTemplate cmp_node_normalize_in[] = {
 
38
        {   SOCK_FLOAT, 1, N_("Value"),         1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
 
39
        {   -1, 0, ""   }
 
40
};
 
41
static bNodeSocketTemplate cmp_node_normalize_out[] = {
 
42
        {   SOCK_FLOAT, 0, N_("Value")},
 
43
        {   -1, 0, ""   }
 
44
};
104
45
 
105
46
void register_node_type_cmp_normalize(bNodeTreeType *ttype)
106
47
{
109
50
        node_type_base(ttype, &ntype, CMP_NODE_NORMALIZE, "Normalize", NODE_CLASS_OP_VECTOR, NODE_OPTIONS);
110
51
        node_type_socket_templates(&ntype, cmp_node_normalize_in, cmp_node_normalize_out);
111
52
        node_type_size(&ntype, 100, 60, 150);
112
 
        node_type_exec(&ntype, node_composit_exec_normalize);
113
53
        
114
54
        nodeRegisterType(ttype, &ntype);
115
55
}