~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/nodes/composite/nodes/node_composite_invert.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
/** \file blender/nodes/composite/nodes/node_composite_invert.c
 
29
 *  \ingroup cmpnodes
 
30
 */
 
31
 
 
32
#include "node_composite_util.h"
 
33
 
 
34
/* **************** INVERT ******************** */
 
35
static bNodeSocketTemplate cmp_node_invert_in[]= { 
 
36
        { SOCK_FLOAT, 1, "Fac", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, 
 
37
        { SOCK_RGBA, 1, "Color", 1.0f, 1.0f, 1.0f, 1.0f}, 
 
38
        { -1, 0, "" } 
 
39
};
 
40
 
 
41
static bNodeSocketTemplate cmp_node_invert_out[]= { 
 
42
        { SOCK_RGBA, 0, "Color"}, 
 
43
        { -1, 0, "" } 
 
44
};
 
45
 
 
46
static void do_invert(bNode *node, float *out, float *in)
 
47
{
 
48
        if (node->custom1 & CMP_CHAN_RGB) {
 
49
                out[0] = 1.0f - in[0];
 
50
                out[1] = 1.0f - in[1];
 
51
                out[2] = 1.0f - in[2];
 
52
        }
 
53
        else {
 
54
                copy_v3_v3(out, in);
 
55
        }
 
56
                
 
57
        if (node->custom1 & CMP_CHAN_A)
 
58
                out[3] = 1.0f - in[3];
 
59
        else
 
60
                out[3] = in[3];
 
61
}
 
62
 
 
63
static void do_invert_fac(bNode *node, float *out, float *in, float *fac)
 
64
{
 
65
        float col[4], facm;
 
66
 
 
67
        do_invert(node, col, in);
 
68
 
 
69
        /* blend inverted result against original input with fac */
 
70
        facm = 1.0f - fac[0];
 
71
 
 
72
        if (node->custom1 & CMP_CHAN_RGB) {
 
73
                col[0] = fac[0]*col[0] + (facm*in[0]);
 
74
                col[1] = fac[0]*col[1] + (facm*in[1]);
 
75
                col[2] = fac[0]*col[2] + (facm*in[2]);
 
76
        }
 
77
        if (node->custom1 & CMP_CHAN_A)
 
78
                col[3] = fac[0]*col[3] + (facm*in[3]);
 
79
        
 
80
        copy_v4_v4(out, col);
 
81
}
 
82
 
 
83
static void node_composit_exec_invert(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
 
84
{
 
85
        /* stack order in: fac, Image, Image */
 
86
        /* stack order out: Image */
 
87
        float *fac= in[0]->vec;
 
88
        
 
89
        if (out[0]->hasoutput==0) return;
 
90
        
 
91
        /* input no image? then only color operation */
 
92
        if (in[1]->data==NULL && in[0]->data==NULL) {
 
93
                do_invert_fac(node, out[0]->vec, in[1]->vec, fac);
 
94
        }
 
95
        else {
 
96
                /* make output size of first available input image, or then size of fac */
 
97
                CompBuf *cbuf= in[1]->data?in[1]->data:in[0]->data;
 
98
 
 
99
                /* if neither RGB or A toggled on, pass through */
 
100
                if (node->custom1 != 0) {
 
101
                        CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
 
102
                        
 
103
                        if (fac[0] < 1.0f || in[0]->data!=NULL)
 
104
                                composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, fac, do_invert_fac, CB_RGBA, CB_VAL);
 
105
                        else
 
106
                                composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_invert, CB_RGBA);
 
107
                        out[0]->data= stackbuf;
 
108
                        return;
 
109
                        
 
110
                }
 
111
                else {
 
112
                        out[0]->data = pass_on_compbuf(cbuf);
 
113
                        return;
 
114
                }
 
115
        }
 
116
}
 
117
 
 
118
static void node_composit_init_invert(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
 
119
{
 
120
        node->custom1 |= CMP_CHAN_RGB;
 
121
}
 
122
 
 
123
/* custom1 = mix type */
 
124
void register_node_type_cmp_invert(bNodeTreeType *ttype)
 
125
{
 
126
        static bNodeType ntype;
 
127
 
 
128
        node_type_base(ttype, &ntype, CMP_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
 
129
        node_type_socket_templates(&ntype, cmp_node_invert_in, cmp_node_invert_out);
 
130
        node_type_size(&ntype, 120, 120, 140);
 
131
        node_type_init(&ntype, node_composit_init_invert);
 
132
        node_type_exec(&ntype, node_composit_exec_invert);
 
133
 
 
134
        nodeRegisterType(ttype, &ntype);
 
135
}