Blender  V3.3
COM_FilterNode.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_FilterNode.h"
5 #include "BKE_node.h"
7 
8 namespace blender::compositor {
9 
10 FilterNode::FilterNode(bNode *editor_node) : Node(editor_node)
11 {
12  /* pass */
13 }
14 
16  const CompositorContext & /*context*/) const
17 {
18  NodeInput *input_socket = this->get_input_socket(0);
19  NodeInput *input_image_socket = this->get_input_socket(1);
20  NodeOutput *output_socket = this->get_output_socket(0);
21  ConvolutionFilterOperation *operation = nullptr;
22 
23  switch (this->get_bnode()->custom1) {
24  case CMP_FILT_SOFT:
25  operation = new ConvolutionFilterOperation();
26  operation->set3x3Filter(1 / 16.0f,
27  2 / 16.0f,
28  1 / 16.0f,
29  2 / 16.0f,
30  4 / 16.0f,
31  2 / 16.0f,
32  1 / 16.0f,
33  2 / 16.0f,
34  1 / 16.0f);
35  break;
36  case CMP_FILT_SHARP_BOX:
37  operation = new ConvolutionFilterOperation();
38  operation->set3x3Filter(-1, -1, -1, -1, 9, -1, -1, -1, -1);
39  break;
40  case CMP_FILT_LAPLACE:
41  operation = new ConvolutionEdgeFilterOperation();
42  operation->set3x3Filter(-1 / 8.0f,
43  -1 / 8.0f,
44  -1 / 8.0f,
45  -1 / 8.0f,
46  1.0f,
47  -1 / 8.0f,
48  -1 / 8.0f,
49  -1 / 8.0f,
50  -1 / 8.0f);
51  break;
52  case CMP_FILT_SOBEL:
53  operation = new ConvolutionEdgeFilterOperation();
54  operation->set3x3Filter(1, 2, 1, 0, 0, 0, -1, -2, -1);
55  break;
56  case CMP_FILT_PREWITT:
57  operation = new ConvolutionEdgeFilterOperation();
58  operation->set3x3Filter(1, 1, 1, 0, 0, 0, -1, -1, -1);
59  break;
60  case CMP_FILT_KIRSCH:
61  operation = new ConvolutionEdgeFilterOperation();
62  operation->set3x3Filter(5, 5, 5, -3, -3, -3, -2, -2, -2);
63  break;
64  case CMP_FILT_SHADOW:
65  operation = new ConvolutionFilterOperation();
66  operation->set3x3Filter(1, 2, 1, 0, 1, 0, -1, -2, -1);
67  break;
69  operation = new ConvolutionFilterOperation();
70  operation->set3x3Filter(0, -1, 0, -1, 5, -1, 0, -1, 0);
71  break;
72  default:
73  operation = new ConvolutionFilterOperation();
74  operation->set3x3Filter(0, 0, 0, 0, 1, 0, 0, 0, 0);
75  break;
76  }
77  converter.add_operation(operation);
78 
79  converter.map_input_socket(input_image_socket, operation->get_input_socket(0));
80  converter.map_input_socket(input_socket, operation->get_input_socket(1));
81  converter.map_output_socket(output_socket, operation->get_output_socket());
82 
83  converter.add_preview(operation->get_output_socket(0));
84 }
85 
86 } // namespace blender::compositor
#define CMP_FILT_PREWITT
Definition: BKE_node.h:1310
#define CMP_FILT_SHARP_BOX
Definition: BKE_node.h:1307
#define CMP_FILT_SOFT
Definition: BKE_node.h:1306
#define CMP_FILT_SHARP_DIAMOND
Definition: BKE_node.h:1313
#define CMP_FILT_LAPLACE
Definition: BKE_node.h:1308
#define CMP_FILT_SOBEL
Definition: BKE_node.h:1309
#define CMP_FILT_KIRSCH
Definition: BKE_node.h:1311
#define CMP_FILT_SHADOW
Definition: BKE_node.h:1312
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 convert_to_operations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
FilterNode(bNode *editor_node)
void map_output_socket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void add_preview(NodeOperationOutput *output)
void add_operation(NodeOperation *operation)
void map_input_socket(NodeInput *node_socket, NodeOperationInput *operation_socket)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:190
NodeOperationOutput * get_output_socket(unsigned int index=0)
NodeOperationInput * get_input_socket(unsigned int index)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:238
NodeOutput * get_output_socket(unsigned int index=0) const
Definition: COM_Node.cc:84
bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:64
NodeInput * get_input_socket(unsigned int index) const
Definition: COM_Node.cc:89