1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2006 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Bob Holcomb, Xavier Thomas
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/nodes/composite/nodes/node_composite_colorSpill.c
* \ingroup cmpnodes
*/
#include "node_composite_util.h"
#define avg(a,b) ((a+b)/2)
/* ******************* Color Spill Supression ********************************* */
static bNodeSocketTemplate cmp_node_color_spill_in[]={
{SOCK_RGBA,1,"Image", 0.8f, 0.8f, 0.8f, 1.0f},
{SOCK_FLOAT, 1, "Fac", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR},
{-1,0,""}
};
static bNodeSocketTemplate cmp_node_color_spill_out[]={
{SOCK_RGBA,0,"Image"},
{-1,0,""}
};
static void do_simple_spillmap_red(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[0]-( ncs->limscale * in[ncs->limchan] );
}
static void do_simple_spillmap_red_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[0]-( ncs->limscale * in[ncs->limchan]));
}
static void do_simple_spillmap_green(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[1]-( ncs->limscale * in[ncs->limchan] );
}
static void do_simple_spillmap_green_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[1]-( ncs->limscale * in[ncs->limchan]));
}
static void do_simple_spillmap_blue(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[2]-( ncs->limscale * in[ncs->limchan] );
}
static void do_simple_spillmap_blue_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[2]-( ncs->limscale * in[ncs->limchan]));
}
static void do_average_spillmap_red(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[0]-(ncs->limscale * avg(in[1], in[2]) );
}
static void do_average_spillmap_red_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[0]-(ncs->limscale * avg(in[1], in[2]) ));
}
static void do_average_spillmap_green(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[1]-(ncs->limscale * avg(in[0], in[2]) );
}
static void do_average_spillmap_green_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[0]-(ncs->limscale * avg(in[0], in[2]) ));
}
static void do_average_spillmap_blue(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[2]-(ncs->limscale * avg(in[0], in[1]) );
}
static void do_average_spillmap_blue_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[0]-(ncs->limscale * avg(in[0], in[1]) ));
}
static void do_apply_spillmap_red(bNode *node, float* out, float *in, float *map)
{
NodeColorspill *ncs;
ncs=node->storage;
if(map[0]>0) {
out[0]=in[0]-(ncs->uspillr*map[0]);
out[1]=in[1]+(ncs->uspillg*map[0]);
out[2]=in[2]+(ncs->uspillb*map[0]);
}
else {
out[0]=in[0];
out[1]=in[1];
out[2]=in[2];
}
}
static void do_apply_spillmap_green(bNode *node, float* out, float *in, float *map)
{
NodeColorspill *ncs;
ncs=node->storage;
if(map[0]>0) {
out[0]=in[0]+(ncs->uspillr*map[0]);
out[1]=in[1]-(ncs->uspillg*map[0]);
out[2]=in[2]+(ncs->uspillb*map[0]);
}
else {
out[0]=in[0];
out[1]=in[1];
out[2]=in[2];
}
}
static void do_apply_spillmap_blue(bNode *node, float* out, float *in, float *map)
{
NodeColorspill *ncs;
ncs=node->storage;
if(map[0]>0) {
out[0]=in[0]+(ncs->uspillr*map[0]);
out[1]=in[1]+(ncs->uspillg*map[0]);
out[2]=in[2]-(ncs->uspillb*map[0]);
}
else {
out[0]=in[0];
out[1]=in[1];
out[2]=in[2];
}
}
static void node_composit_exec_color_spill(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* Originally based on the information from the book "The Art and Science of Digital Composition" and
* discussions from vfxtalk.com .*/
CompBuf *cbuf;
/* CompBuf *mask; */ /* UNUSED */
CompBuf *rgbbuf;
CompBuf *spillmap;
NodeColorspill *ncs;
ncs=node->storage;
/* early out for missing connections */
if(out[0]->hasoutput==0 ) return;
if(in[0]->hasinput==0) return;
if(in[0]->data==NULL) return;
cbuf=typecheck_compbuf(in[0]->data, CB_RGBA);
/* mask= */ /* UNUSED */ typecheck_compbuf(in[1]->data, CB_VAL);
spillmap=alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1);
rgbbuf=dupalloc_compbuf(cbuf);
switch(node->custom1)
{
case 1: /*red spill*/
{
switch(node->custom2)
{
case 0: /* simple limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_red, CB_RGBA);
} else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_red_fac, CB_RGBA, CB_VAL);
}
break;
}
case 1: /* average limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_red, CB_RGBA);
} else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_red_fac, CB_RGBA, CB_VAL);
}
break;
}
}
if(ncs->unspill==0) {
ncs->uspillr=1.0f;
ncs->uspillg=0.0f;
ncs->uspillb=0.0f;
}
composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_red, CB_RGBA, CB_VAL);
break;
}
case 2: /*green spill*/
{
switch(node->custom2)
{
case 0: /* simple limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_green, CB_RGBA);
} else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_green_fac, CB_RGBA, CB_VAL);
}
break;
}
case 1: /* average limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_green, CB_RGBA);
} else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_green_fac, CB_RGBA, CB_VAL);
}
break;
}
}
if(ncs->unspill==0) {
ncs->uspillr=0.0f;
ncs->uspillg=1.0f;
ncs->uspillb=0.0f;
}
composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_green, CB_RGBA, CB_VAL);
break;
}
case 3: /*blue spill*/
{
switch(node->custom2)
{
case 0: /* simple limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_blue, CB_RGBA);
} else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_blue_fac, CB_RGBA, CB_VAL);
}
break;
}
case 1: /* average limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_blue, CB_RGBA);
} else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_blue_fac, CB_RGBA, CB_VAL);
}
break;
}
}
if(ncs->unspill==0) {
ncs->uspillr=0.0f;
ncs->uspillg=0.0f;
ncs->uspillb=1.0f;
}
composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_blue, CB_RGBA, CB_VAL);
break;
}
default:
break;
}
out[0]->data=rgbbuf;
if(cbuf!=in[0]->data)
free_compbuf(cbuf);
free_compbuf(spillmap);
}
static void node_composit_init_color_spill(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
{
NodeColorspill *ncs= MEM_callocN(sizeof(NodeColorspill), "node colorspill");
node->storage=ncs;
node->custom1= 2; /* green channel */
node->custom2= 0; /* simple limit algo*/
ncs->limchan= 0; /* limit by red */
ncs->limscale= 1.0f; /* limit scaling factor */
ncs->unspill=0; /* do not use unspill */
}
void register_node_type_cmp_color_spill(ListBase *lb)
{
static bNodeType ntype;
node_type_base(&ntype, CMP_NODE_COLOR_SPILL, "Color Spill", NODE_CLASS_MATTE, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_color_spill_in, cmp_node_color_spill_out);
node_type_size(&ntype, 140, 80, 200);
node_type_init(&ntype, node_composit_init_color_spill);
node_type_storage(&ntype, "NodeColorspill", node_free_standard_storage, node_copy_standard_storage);
node_type_exec(&ntype, node_composit_exec_color_spill);
nodeRegisterType(lb, &ntype);
}
|