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
|
/*
* Copyright 2011, Blender Foundation.
*
* This Reader 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 Reader 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 Reader; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
#include "COM_ColorSpillOperation.h"
#include "BLI_math.h"
#define avg(a,b) ((a+b)/2)
ColorSpillOperation::ColorSpillOperation(): NodeOperation()
{
addInputSocket(COM_DT_COLOR);
addInputSocket(COM_DT_VALUE);
addOutputSocket(COM_DT_COLOR);
inputImageReader = NULL;
inputFacReader = NULL;
this->spillChannel = 1; // GREEN
}
void ColorSpillOperation::initExecution()
{
this->inputImageReader = this->getInputSocketReader(0);
this->inputFacReader = this->getInputSocketReader(1);
if (spillChannel == 0) {
this->rmut = -1.0f;
this->gmut = 1.0f;
this->bmut = 1.0f;
this->channel2 = 1;
this->channel3 = 2;
if (this->settings->unspill == 0) {
this->settings->uspillr = 1.0f;
this->settings->uspillg = 0.0f;
this->settings->uspillb = 0.0f;
}
}
else if (spillChannel == 1) {
this->rmut = 1.0f;
this->gmut = -1.0f;
this->bmut = 1.0f;
this->channel2 = 0;
this->channel3 = 2;
if (this->settings->unspill == 0) {
this->settings->uspillr = 0.0f;
this->settings->uspillg = 1.0f;
this->settings->uspillb = 0.0f;
}
}
else {
this->rmut = 1.0f;
this->gmut = 1.0f;
this->bmut = -1.0f;
this->channel2 = 0;
this->channel3 = 1;
if (this->settings->unspill == 0) {
this->settings->uspillr = 0.0f;
this->settings->uspillg = 0.0f;
this->settings->uspillb = 1.0f;
}
}
}
void ColorSpillOperation::deinitExecution()
{
this->inputImageReader = NULL;
this->inputFacReader = NULL;
}
void ColorSpillOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
{
float fac[4];
float input[4];
this->inputFacReader->read(fac, x, y, sampler, inputBuffers);
this->inputImageReader->read(input, x, y, sampler, inputBuffers);
float rfac = min(1.0f, fac[0]);
float map = calculateMapValue(rfac, input);
if (map > 0.0f) {
outputValue[0] = input[0] + this->rmut * (this->settings->uspillr * map);
outputValue[1] = input[1] + this->gmut * (this->settings->uspillg * map);
outputValue[2] = input[2] + this->bmut * (this->settings->uspillb * map);
outputValue[3] = input[3];
}
else {
copy_v4_v4(outputValue, input);
}
}
float ColorSpillOperation::calculateMapValue(float fac, float *input)
{
return fac * (input[this->spillChannel]-(this->settings->limscale*input[this->settings->limchan]));
}
float ColorSpillAverageOperation::calculateMapValue(float fac, float *input)
{
return fac * (input[this->spillChannel]-(this->settings->limscale*avg(input[this->channel2], input[this->channel3])));
}
|