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

« back to all changes in this revision

Viewing changes to source/blender/nodes/composite/nodes/node_composite_brightness.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:
36
36
 
37
37
/* **************** Brigh and contrsast  ******************** */
38
38
 
39
 
static bNodeSocketTemplate cmp_node_brightcontrast_in[]= {
40
 
        {       SOCK_RGBA, 1, "Image",                  1.0f, 1.0f, 1.0f, 1.0f},
41
 
        {       SOCK_FLOAT, 1, "Bright",                0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE},
42
 
        {       SOCK_FLOAT, 1, "Contrast",              0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE},
43
 
        {       -1, 0, ""       }
44
 
};
45
 
static bNodeSocketTemplate cmp_node_brightcontrast_out[]= {
46
 
        {       SOCK_RGBA, 0, "Image"},
47
 
        {       -1, 0, ""       }
48
 
};
49
 
 
50
 
static void do_brightnesscontrast(bNode *UNUSED(node), float *out, float *in, float *in_brightness, float *in_contrast)
51
 
{
52
 
        float i;
53
 
        int c;
54
 
        float a, b, v;
55
 
        float brightness = (*in_brightness) / 100.0f;
56
 
        float contrast = *in_contrast;
57
 
        float delta = contrast / 200.0f;
58
 
        a = 1.0f - delta * 2.0f;
59
 
        /*
60
 
        * The algorithm is by Werner D. Streidt
61
 
        * (http://visca.com/ffactory/archives/5-99/msg00021.html)
62
 
        * Extracted of OpenCV demhist.c
63
 
        */
64
 
        if (contrast > 0) {
65
 
                a = 1.0f / a;
66
 
                b = a * (brightness - delta);
67
 
        }
68
 
        else {
69
 
                delta *= -1;
70
 
                b = a * (brightness + delta);
71
 
        }
72
 
        
73
 
        for (c=0; c<3; c++) {        
74
 
                i = in[c];
75
 
                v = a*i + b;
76
 
                out[c] = v;
77
 
        }
78
 
}
79
 
 
80
 
static void node_composit_exec_brightcontrast(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
81
 
{
82
 
        if (out[0]->hasoutput==0)
83
 
                return;
84
 
        
85
 
        if (in[0]->data) {
86
 
                CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
87
 
                stackbuf= dupalloc_compbuf(cbuf);
88
 
                composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, do_brightnesscontrast, CB_RGBA, CB_VAL, CB_VAL);
89
 
                out[0]->data = stackbuf;
90
 
                if (cbuf != in[0]->data)
91
 
                        free_compbuf(cbuf);
92
 
        }
93
 
}
 
39
static bNodeSocketTemplate cmp_node_brightcontrast_in[] = {
 
40
        {       SOCK_RGBA, 1, N_("Image"),                      1.0f, 1.0f, 1.0f, 1.0f},
 
41
        {       SOCK_FLOAT, 1, N_("Bright"),            0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE},
 
42
        {       SOCK_FLOAT, 1, N_("Contrast"),          0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE},
 
43
        {       -1, 0, ""       }
 
44
};
 
45
static bNodeSocketTemplate cmp_node_brightcontrast_out[] = {
 
46
        {       SOCK_RGBA, 0, N_("Image")},
 
47
        {       -1, 0, ""       }
 
48
};
 
49
 
94
50
 
95
51
void register_node_type_cmp_brightcontrast(bNodeTreeType *ttype)
96
52
{
99
55
        node_type_base(ttype, &ntype, CMP_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
100
56
        node_type_socket_templates(&ntype, cmp_node_brightcontrast_in, cmp_node_brightcontrast_out);
101
57
        node_type_size(&ntype, 140, 100, 320);
102
 
        node_type_exec(&ntype, node_composit_exec_brightcontrast);
103
 
        
 
58
 
104
59
        nodeRegisterType(ttype, &ntype);
105
60
}