Color Management, Stage 2: Switch color pipeline to use OpenColorIO
[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
35 BlurNode::BlurNode(bNode *editorNode) : Node(editorNode)
36 {
37         /* pass */
38 }
39
40 void BlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
41 {
42         bNode *editorNode = this->getbNode();
43         NodeBlurData *data = (NodeBlurData *)editorNode->storage;
44         InputSocket *inputSizeSocket = this->getInputSocket(1);
45         bool connectedSizeSocket = inputSizeSocket->isConnected();
46
47         const bNodeSocket *sock = this->getInputSocket(1)->getbNodeSocket();
48         const float size = ((const bNodeSocketValueFloat *)sock->default_value)->value;
49         
50         CompositorQuality quality = context->getQuality();
51         
52         if (data->filtertype == R_FILTER_FAST_GAUSS) {
53                 FastGaussianBlurOperation *operationfgb = new FastGaussianBlurOperation();
54                 operationfgb->setData(data);
55                 operationfgb->setbNode(editorNode);
56                 this->getInputSocket(0)->relinkConnections(operationfgb->getInputSocket(0), 0, graph);
57                 this->getInputSocket(1)->relinkConnections(operationfgb->getInputSocket(1), 1, graph);
58                 this->getOutputSocket(0)->relinkConnections(operationfgb->getOutputSocket(0));
59                 graph->addOperation(operationfgb);
60                 addPreviewOperation(graph, context, operationfgb->getOutputSocket());
61         }
62         else if (editorNode->custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE) {
63                 MathAddOperation *clamp = new MathAddOperation();
64                 SetValueOperation *zero = new SetValueOperation();
65                 addLink(graph, zero->getOutputSocket(), clamp->getInputSocket(1));
66                 this->getInputSocket(1)->relinkConnections(clamp->getInputSocket(0), 1, graph);
67                 zero->setValue(0.0f);
68                 clamp->setUseClamp(true);
69                 graph->addOperation(clamp);
70                 graph->addOperation(zero);
71         
72                 GaussianAlphaXBlurOperation *operationx = new GaussianAlphaXBlurOperation();
73                 operationx->setData(data);
74                 operationx->setbNode(editorNode);
75                 operationx->setQuality(quality);
76                 operationx->setSize(1.0f);
77                 operationx->setFalloff(PROP_SMOOTH);
78                 operationx->setSubtract(false);
79                 addLink(graph, clamp->getOutputSocket(), operationx->getInputSocket(0));
80                 graph->addOperation(operationx);
81
82                 GaussianAlphaYBlurOperation *operationy = new GaussianAlphaYBlurOperation();
83                 operationy->setData(data);
84                 operationy->setbNode(editorNode);
85                 operationy->setQuality(quality);
86                 operationy->setSize(1.0f);
87                 operationy->setFalloff(PROP_SMOOTH);
88                 operationy->setSubtract(false);
89                 addLink(graph, operationx->getOutputSocket(), operationy->getInputSocket(0));
90                 graph->addOperation(operationy);
91
92                 GaussianBlurReferenceOperation *operation = new GaussianBlurReferenceOperation();
93                 operation->setData(data);
94                 operation->setbNode(editorNode);
95                 operation->setQuality(quality);
96                 this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
97                 addLink(graph, operationy->getOutputSocket(), operation->getInputSocket(1));
98                 graph->addOperation(operation);
99                 this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
100                 addPreviewOperation(graph, context, operation->getOutputSocket());
101         }
102         else if (!data->bokeh) {
103                 GaussianXBlurOperation *operationx = new GaussianXBlurOperation();
104                 operationx->setData(data);
105                 operationx->setbNode(editorNode);
106                 operationx->setQuality(quality);
107                 this->getInputSocket(0)->relinkConnections(operationx->getInputSocket(0), 0, graph);
108                 this->getInputSocket(1)->relinkConnections(operationx->getInputSocket(1), 1, graph);
109                 graph->addOperation(operationx);
110                 GaussianYBlurOperation *operationy = new GaussianYBlurOperation();
111                 operationy->setData(data);
112                 operationy->setbNode(editorNode);
113                 operationy->setQuality(quality);
114                 this->getOutputSocket(0)->relinkConnections(operationy->getOutputSocket());
115                 graph->addOperation(operationy);
116                 addLink(graph, operationx->getOutputSocket(), operationy->getInputSocket(0));
117                 addLink(graph, operationx->getInputSocket(1)->getConnection()->getFromSocket(), operationy->getInputSocket(1));
118                 addPreviewOperation(graph, context, operationy->getOutputSocket());
119
120                 if (!connectedSizeSocket) {
121                         operationx->setSize(size);
122                         operationy->setSize(size);
123                 }
124         }
125         else {
126                 GaussianBokehBlurOperation *operation = new GaussianBokehBlurOperation();
127                 operation->setData(data);
128                 operation->setbNode(editorNode);
129                 this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
130                 this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph);
131                 operation->setQuality(quality);
132                 graph->addOperation(operation);
133                 this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
134                 addPreviewOperation(graph, context, operation->getOutputSocket());
135
136                 if (!connectedSizeSocket) {
137                         operation->setSize(size);
138                 }
139         }
140 }