Cleanup: comment line length (editors)
[blender.git] / source / blender / compositor / nodes / COM_BlurNode.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
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  * Contributor:
19  *      Jeroen Bakker
20  *      Monique Dewanchand
21  */
22
23 #include "COM_BlurNode.h"
24 #include "DNA_node_types.h"
25 #include "COM_GaussianXBlurOperation.h"
26 #include "COM_GaussianYBlurOperation.h"
27 #include "COM_GaussianAlphaXBlurOperation.h"
28 #include "COM_GaussianAlphaYBlurOperation.h"
29 #include "COM_ExecutionSystem.h"
30 #include "COM_GaussianBokehBlurOperation.h"
31 #include "COM_FastGaussianBlurOperation.h"
32 #include "COM_MathBaseOperation.h"
33 #include "COM_SetValueOperation.h"
34 #include "COM_GammaCorrectOperation.h"
35
36 BlurNode::BlurNode(bNode *editorNode) : Node(editorNode)
37 {
38         /* pass */
39 }
40
41 void BlurNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
42 {
43         bNode *editorNode = this->getbNode();
44         NodeBlurData *data = (NodeBlurData *)editorNode->storage;
45         NodeInput *inputSizeSocket = this->getInputSocket(1);
46         bool connectedSizeSocket = inputSizeSocket->isLinked();
47
48         const float size = this->getInputSocket(1)->getEditorValueFloat();
49         const bool extend_bounds = (editorNode->custom1 & CMP_NODEFLAG_BLUR_EXTEND_BOUNDS) != 0;
50
51         CompositorQuality quality = context.getQuality();
52         NodeOperation *input_operation = NULL, *output_operation = NULL;
53
54         if (data->filtertype == R_FILTER_FAST_GAUSS) {
55                 FastGaussianBlurOperation *operationfgb = new FastGaussianBlurOperation();
56                 operationfgb->setData(data);
57                 operationfgb->setExtendBounds(extend_bounds);
58                 converter.addOperation(operationfgb);
59
60                 converter.mapInputSocket(getInputSocket(1), operationfgb->getInputSocket(1));
61
62                 input_operation = operationfgb;
63                 output_operation = operationfgb;
64         }
65         else if (editorNode->custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE) {
66                 MathAddOperation *clamp = new MathAddOperation();
67                 SetValueOperation *zero = new SetValueOperation();
68                 zero->setValue(0.0f);
69                 clamp->setUseClamp(true);
70
71                 converter.addOperation(clamp);
72                 converter.addOperation(zero);
73                 converter.mapInputSocket(getInputSocket(1), clamp->getInputSocket(0));
74                 converter.addLink(zero->getOutputSocket(), clamp->getInputSocket(1));
75
76                 GaussianAlphaXBlurOperation *operationx = new GaussianAlphaXBlurOperation();
77                 operationx->setData(data);
78                 operationx->setQuality(quality);
79                 operationx->setSize(1.0f);
80                 operationx->setFalloff(PROP_SMOOTH);
81                 operationx->setSubtract(false);
82                 operationx->setExtendBounds(extend_bounds);
83
84                 converter.addOperation(operationx);
85                 converter.addLink(clamp->getOutputSocket(), operationx->getInputSocket(0));
86
87                 GaussianAlphaYBlurOperation *operationy = new GaussianAlphaYBlurOperation();
88                 operationy->setData(data);
89                 operationy->setQuality(quality);
90                 operationy->setSize(1.0f);
91                 operationy->setFalloff(PROP_SMOOTH);
92                 operationy->setSubtract(false);
93                 operationy->setExtendBounds(extend_bounds);
94
95                 converter.addOperation(operationy);
96                 converter.addLink(operationx->getOutputSocket(), operationy->getInputSocket(0));
97
98                 GaussianBlurReferenceOperation *operation = new GaussianBlurReferenceOperation();
99                 operation->setData(data);
100                 operation->setQuality(quality);
101                 operation->setExtendBounds(extend_bounds);
102
103                 converter.addOperation(operation);
104                 converter.addLink(operationy->getOutputSocket(), operation->getInputSocket(1));
105
106                 output_operation = operation;
107                 input_operation = operation;
108         }
109         else if (!data->bokeh) {
110                 GaussianXBlurOperation *operationx = new GaussianXBlurOperation();
111                 operationx->setData(data);
112                 operationx->setQuality(quality);
113                 operationx->checkOpenCL();
114                 operationx->setExtendBounds(extend_bounds);
115
116                 converter.addOperation(operationx);
117                 converter.mapInputSocket(getInputSocket(1), operationx->getInputSocket(1));
118
119                 GaussianYBlurOperation *operationy = new GaussianYBlurOperation();
120                 operationy->setData(data);
121                 operationy->setQuality(quality);
122                 operationy->checkOpenCL();
123                 operationy->setExtendBounds(extend_bounds);
124
125                 converter.addOperation(operationy);
126                 converter.mapInputSocket(getInputSocket(1), operationy->getInputSocket(1));
127                 converter.addLink(operationx->getOutputSocket(), operationy->getInputSocket(0));
128
129                 if (!connectedSizeSocket) {
130                         operationx->setSize(size);
131                         operationy->setSize(size);
132                 }
133
134                 input_operation = operationx;
135                 output_operation = operationy;
136         }
137         else {
138                 GaussianBokehBlurOperation *operation = new GaussianBokehBlurOperation();
139                 operation->setData(data);
140                 operation->setQuality(quality);
141                 operation->setExtendBounds(extend_bounds);
142
143                 converter.addOperation(operation);
144                 converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1));
145
146                 if (!connectedSizeSocket) {
147                         operation->setSize(size);
148                 }
149
150                 input_operation = operation;
151                 output_operation = operation;
152         }
153
154         if (data->gamma) {
155                 GammaCorrectOperation *correct = new GammaCorrectOperation();
156                 GammaUncorrectOperation *inverse = new GammaUncorrectOperation();
157                 converter.addOperation(correct);
158                 converter.addOperation(inverse);
159
160                 converter.mapInputSocket(getInputSocket(0), correct->getInputSocket(0));
161                 converter.addLink(correct->getOutputSocket(), input_operation->getInputSocket(0));
162                 converter.addLink(output_operation->getOutputSocket(), inverse->getInputSocket(0));
163                 converter.mapOutputSocket(getOutputSocket(), inverse->getOutputSocket());
164
165                 converter.addPreview(inverse->getOutputSocket());
166         }
167         else {
168                 converter.mapInputSocket(getInputSocket(0), input_operation->getInputSocket(0));
169                 converter.mapOutputSocket(getOutputSocket(), output_operation->getOutputSocket());
170
171                 converter.addPreview(output_operation->getOutputSocket());
172         }
173 }