2
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18
* The Original Code is Copyright (C) 2006 Blender Foundation.
19
* All rights reserved.
21
* The Original Code is: all of this file.
23
* Contributor(s): none yet.
25
* ***** END GPL LICENSE BLOCK *****
28
/** \file blender/nodes/composite/nodes/node_composite_invert.c
32
#include "node_composite_util.h"
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},
41
static bNodeSocketTemplate cmp_node_invert_out[]= {
42
{ SOCK_RGBA, 0, "Color"},
46
static void do_invert(bNode *node, float *out, float *in)
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];
57
if (node->custom1 & CMP_CHAN_A)
58
out[3] = 1.0f - in[3];
63
static void do_invert_fac(bNode *node, float *out, float *in, float *fac)
67
do_invert(node, col, in);
69
/* blend inverted result against original input with fac */
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]);
77
if (node->custom1 & CMP_CHAN_A)
78
col[3] = fac[0]*col[3] + (facm*in[3]);
83
static void node_composit_exec_invert(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
85
/* stack order in: fac, Image, Image */
86
/* stack order out: Image */
87
float *fac= in[0]->vec;
89
if (out[0]->hasoutput==0) return;
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);
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;
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 */
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);
106
composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_invert, CB_RGBA);
107
out[0]->data= stackbuf;
112
out[0]->data = pass_on_compbuf(cbuf);
118
static void node_composit_init_invert(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
120
node->custom1 |= CMP_CHAN_RGB;
123
/* custom1 = mix type */
124
void register_node_type_cmp_invert(bNodeTreeType *ttype)
126
static bNodeType ntype;
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);
134
nodeRegisterType(ttype, &ntype);