~siretart/ubuntu/utopic/blender/libav10

« 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): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version. 
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 * 
 
18
 * The Original Code is Copyright (C) 2006 Blender Foundation.
 
19
 * All rights reserved.
 
20
 * 
 
21
 * The Original Code is: all of this file.
 
22
 * 
 
23
 * Contributor(s): none yet.
 
24
 * 
 
25
 * ***** END GPL LICENSE BLOCK *****
 
26
 
 
27
*/
 
28
 
 
29
/** \file blender/nodes/composite/nodes/node_composite_brightness.c
 
30
 *  \ingroup cmpnodes
 
31
 */
 
32
 
 
33
 
 
34
#include "node_composite_util.h"
 
35
 
 
36
 
 
37
/* **************** Brigh and contrsast  ******************** */
 
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
}
 
94
 
 
95
void register_node_type_cmp_brightcontrast(bNodeTreeType *ttype)
 
96
{
 
97
        static bNodeType ntype;
 
98
        
 
99
        node_type_base(ttype, &ntype, CMP_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
 
100
        node_type_socket_templates(&ntype, cmp_node_brightcontrast_in, cmp_node_brightcontrast_out);
 
101
        node_type_size(&ntype, 140, 100, 320);
 
102
        node_type_exec(&ntype, node_composit_exec_brightcontrast);
 
103
        
 
104
        nodeRegisterType(ttype, &ntype);
 
105
}