2 * Copyright 2011, Blender Foundation.
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.
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.
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.
23 #include "COM_FilterNode.h"
24 #include "COM_ConvolutionFilterOperation.h"
25 #include "COM_ConvolutionEdgeFilterOperation.h"
26 #include "COM_ExecutionSystem.h"
28 #include "COM_MixOperation.h"
30 FilterNode::FilterNode(bNode *editorNode) : Node(editorNode)
35 void FilterNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const
37 NodeInput *inputSocket = this->getInputSocket(0);
38 NodeInput *inputImageSocket = this->getInputSocket(1);
39 NodeOutput *outputSocket = this->getOutputSocket(0);
40 ConvolutionFilterOperation *operation = NULL;
42 switch (this->getbNode()->custom1) {
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);
48 operation = new ConvolutionFilterOperation();
49 operation->set3x3Filter(-1, -1, -1, -1, 9, -1, -1, -1, -1);
51 case CMP_FILT_LAPLACE:
52 operation = new ConvolutionEdgeFilterOperation();
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);
56 operation = new ConvolutionEdgeFilterOperation();
57 operation->set3x3Filter(1, 2, 1, 0, 0, 0, -1, -2, -1);
59 case CMP_FILT_PREWITT:
60 operation = new ConvolutionEdgeFilterOperation();
61 operation->set3x3Filter(1, 1, 1, 0, 0, 0, -1, -1, -1);
64 operation = new ConvolutionEdgeFilterOperation();
65 operation->set3x3Filter(5, 5, 5, -3, -3, -3, -2, -2, -2);
68 operation = new ConvolutionFilterOperation();
69 operation->set3x3Filter(1, 2, 1, 0, 1, 0, -1, -2, -1);
72 operation = new ConvolutionFilterOperation();
73 operation->set3x3Filter(0, 0, 0, 0, 1, 0, 0, 0, 0);
76 converter.addOperation(operation);
78 converter.mapInputSocket(inputImageSocket, operation->getInputSocket(0));
79 converter.mapInputSocket(inputSocket, operation->getInputSocket(1));
80 converter.mapOutputSocket(outputSocket, operation->getOutputSocket());
82 converter.addPreview(operation->getOutputSocket(0));