Color management: use partial buffer update when painting image
[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, 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                 addLink(graph, clamp->getOutputSocket(), operationx->getInputSocket(0));
78                 graph->addOperation(operationx);
79
80                 GaussianYBlurOperation *operationy = new GaussianYBlurOperation();
81                 operationy->setData(data);
82                 operationy->setbNode(editorNode);
83                 operationy->setQuality(quality);
84                 operationy->setSize(1.0f);
85                 addLink(graph, operationx->getOutputSocket(), operationy->getInputSocket(0));
86                 graph->addOperation(operationy);
87
88                 GaussianBlurReferenceOperation *operation = new GaussianBlurReferenceOperation();
89                 operation->setData(data);
90                 operation->setbNode(editorNode);
91                 operation->setQuality(quality);
92                 this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
93                 addLink(graph, operationy->getOutputSocket(), operation->getInputSocket(1));
94                 graph->addOperation(operation);
95                 this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
96                 addPreviewOperation(graph, operation->getOutputSocket());
97         }
98         else if (!data->bokeh) {
99                 GaussianXBlurOperation *operationx = new GaussianXBlurOperation();
100                 operationx->setData(data);
101                 operationx->setbNode(editorNode);
102                 operationx->setQuality(quality);
103                 this->getInputSocket(0)->relinkConnections(operationx->getInputSocket(0), 0, graph);
104                 this->getInputSocket(1)->relinkConnections(operationx->getInputSocket(1), 1, graph);
105                 graph->addOperation(operationx);
106                 GaussianYBlurOperation *operationy = new GaussianYBlurOperation();
107                 operationy->setData(data);
108                 operationy->setbNode(editorNode);
109                 operationy->setQuality(quality);
110                 this->getOutputSocket(0)->relinkConnections(operationy->getOutputSocket());
111                 graph->addOperation(operationy);
112                 addLink(graph, operationx->getOutputSocket(), operationy->getInputSocket(0));
113                 addLink(graph, operationx->getInputSocket(1)->getConnection()->getFromSocket(), operationy->getInputSocket(1));
114                 addPreviewOperation(graph, operationy->getOutputSocket());
115
116                 if (!connectedSizeSocket) {
117                         operationx->setSize(size);
118                         operationy->setSize(size);
119                 }
120         }
121         else {
122                 GaussianBokehBlurOperation *operation = new GaussianBokehBlurOperation();
123                 operation->setData(data);
124                 operation->setbNode(editorNode);
125                 this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
126                 this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph);
127                 operation->setQuality(quality);
128                 graph->addOperation(operation);
129                 this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
130                 addPreviewOperation(graph, operation->getOutputSocket());
131
132                 if (!connectedSizeSocket) {
133                         operation->setSize(size);
134                 }
135         }
136 }