Color Management, Stage 2: Switch color pipeline to use OpenColorIO
[blender.git] / source / blender / compositor / nodes / COM_FilterNode.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_FilterNode.h"
24 #include "COM_ConvolutionFilterOperation.h"
25 #include "COM_ConvolutionEdgeFilterOperation.h"
26 #include "COM_ExecutionSystem.h"
27 #include "BKE_node.h"
28 #include "COM_MixBlendOperation.h"
29
30 FilterNode::FilterNode(bNode *editorNode) : Node(editorNode)
31 {
32         /* pass */
33 }
34
35 void FilterNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
36 {
37         InputSocket *inputSocket = this->getInputSocket(0);
38         InputSocket *inputImageSocket = this->getInputSocket(1);
39         OutputSocket *outputSocket = this->getOutputSocket(0);
40         ConvolutionFilterOperation *operation = NULL;
41         
42         switch (this->getbNode()->custom1) {
43                 case CMP_FILT_SOFT:
44                         operation = new ConvolutionFilterOperation();
45                         operation->set3x3Filter(1 / 16.0f, 2 / 16.0f, 1 / 16.0f, 2 / 16.0f, 4 / 16.0f, 2 / 16.0f, 1 / 16.0f, 2 / 16.0f, 1 / 16.0f);
46                         break;
47                 case CMP_FILT_SHARP:
48                         operation = new ConvolutionFilterOperation();
49                         operation->set3x3Filter(-1, -1, -1, -1, 9, -1, -1, -1, -1);
50                         break;
51                 case CMP_FILT_LAPLACE:
52                         operation = new ConvolutionFilterOperation();
53                         operation->set3x3Filter(-1 / 8.0f, -1 / 8.0f, -1 / 8.0f, -1 / 8.0f, 1.0f, -1 / 8.0f, -1 / 8.0f, -1 / 8.0f, -1 / 8.0f);
54                         break;
55                 case CMP_FILT_SOBEL:
56                         operation = new ConvolutionEdgeFilterOperation();
57                         operation->set3x3Filter(1, 2, 1, 0, 0, 0, -1, -2, -1);
58                         break;
59                 case CMP_FILT_PREWITT:
60                         operation = new ConvolutionEdgeFilterOperation();
61                         operation->set3x3Filter(1, 1, 1, 0, 0, 0, -1, -1, -1);
62                         break;
63                 case CMP_FILT_KIRSCH:
64                         operation = new ConvolutionEdgeFilterOperation();
65                         operation->set3x3Filter(5, 5, 5, -3, -3, -3, -2, -2, -2);
66                         break;
67                 case CMP_FILT_SHADOW:
68                         operation = new ConvolutionFilterOperation();
69                         operation->set3x3Filter(1, 2, 1, 0, 1, 0, -1, -2, -1);
70                         break;
71                 default:
72                         operation = new ConvolutionFilterOperation();
73                         operation->set3x3Filter(0, 0, 0, 0, 1, 0, 0, 0, 0);
74                         break;
75         }
76         operation->setbNode(this->getbNode());
77         inputImageSocket->relinkConnections(operation->getInputSocket(0), 1, graph);
78         inputSocket->relinkConnections(operation->getInputSocket(1), 0, graph);
79         outputSocket->relinkConnections(operation->getOutputSocket());
80         addPreviewOperation(graph, context, operation->getOutputSocket(0));
81         
82         graph->addOperation(operation);
83 }