Blender  V2.93
COM_FilterNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_FilterNode.h"
20 #include "BKE_node.h"
23 #include "COM_ExecutionSystem.h"
24 #include "COM_MixOperation.h"
25 
26 namespace blender::compositor {
27 
28 FilterNode::FilterNode(bNode *editorNode) : Node(editorNode)
29 {
30  /* pass */
31 }
32 
34  const CompositorContext & /*context*/) const
35 {
36  NodeInput *inputSocket = this->getInputSocket(0);
37  NodeInput *inputImageSocket = this->getInputSocket(1);
38  NodeOutput *outputSocket = this->getOutputSocket(0);
39  ConvolutionFilterOperation *operation = nullptr;
40 
41  switch (this->getbNode()->custom1) {
42  case CMP_FILT_SOFT:
43  operation = new ConvolutionFilterOperation();
44  operation->set3x3Filter(1 / 16.0f,
45  2 / 16.0f,
46  1 / 16.0f,
47  2 / 16.0f,
48  4 / 16.0f,
49  2 / 16.0f,
50  1 / 16.0f,
51  2 / 16.0f,
52  1 / 16.0f);
53  break;
54  case CMP_FILT_SHARP:
55  operation = new ConvolutionFilterOperation();
56  operation->set3x3Filter(-1, -1, -1, -1, 9, -1, -1, -1, -1);
57  break;
58  case CMP_FILT_LAPLACE:
59  operation = new ConvolutionEdgeFilterOperation();
60  operation->set3x3Filter(-1 / 8.0f,
61  -1 / 8.0f,
62  -1 / 8.0f,
63  -1 / 8.0f,
64  1.0f,
65  -1 / 8.0f,
66  -1 / 8.0f,
67  -1 / 8.0f,
68  -1 / 8.0f);
69  break;
70  case CMP_FILT_SOBEL:
71  operation = new ConvolutionEdgeFilterOperation();
72  operation->set3x3Filter(1, 2, 1, 0, 0, 0, -1, -2, -1);
73  break;
74  case CMP_FILT_PREWITT:
75  operation = new ConvolutionEdgeFilterOperation();
76  operation->set3x3Filter(1, 1, 1, 0, 0, 0, -1, -1, -1);
77  break;
78  case CMP_FILT_KIRSCH:
79  operation = new ConvolutionEdgeFilterOperation();
80  operation->set3x3Filter(5, 5, 5, -3, -3, -3, -2, -2, -2);
81  break;
82  case CMP_FILT_SHADOW:
83  operation = new ConvolutionFilterOperation();
84  operation->set3x3Filter(1, 2, 1, 0, 1, 0, -1, -2, -1);
85  break;
86  default:
87  operation = new ConvolutionFilterOperation();
88  operation->set3x3Filter(0, 0, 0, 0, 1, 0, 0, 0, 0);
89  break;
90  }
91  converter.addOperation(operation);
92 
93  converter.mapInputSocket(inputImageSocket, operation->getInputSocket(0));
94  converter.mapInputSocket(inputSocket, operation->getInputSocket(1));
95  converter.mapOutputSocket(outputSocket, operation->getOutputSocket());
96 
97  converter.addPreview(operation->getOutputSocket(0));
98 }
99 
100 } // namespace blender::compositor
#define CMP_FILT_PREWITT
Definition: BKE_node.h:1239
#define CMP_FILT_SOFT
Definition: BKE_node.h:1235
#define CMP_FILT_SHARP
Definition: BKE_node.h:1236
#define CMP_FILT_LAPLACE
Definition: BKE_node.h:1237
#define CMP_FILT_SOBEL
Definition: BKE_node.h:1238
#define CMP_FILT_KIRSCH
Definition: BKE_node.h:1240
#define CMP_FILT_SHADOW
Definition: BKE_node.h:1241
Overall context of the compositor.
void set3x3Filter(float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9)
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addPreview(NodeOperationOutput *output)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:258
NodeOutput * getOutputSocket(const unsigned int index=0) const
Definition: COM_Node.cc:108
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
NodeInput * getInputSocket(const unsigned int index) const
Definition: COM_Node.cc:113