Welcome to mirror list, hosted at ThFree Co, Russian Federation.

COM_FilterNode.cc « nodes « compositor « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f2efa8caefd047b8a927f213d1d54d9d176562e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright 2011 Blender Foundation. */

#include "COM_FilterNode.h"
#include "BKE_node.h"
#include "COM_ConvolutionEdgeFilterOperation.h"

namespace blender::compositor {

FilterNode::FilterNode(bNode *editor_node) : Node(editor_node)
{
  /* pass */
}

void FilterNode::convert_to_operations(NodeConverter &converter,
                                       const CompositorContext & /*context*/) const
{
  NodeInput *input_socket = this->get_input_socket(0);
  NodeInput *input_image_socket = this->get_input_socket(1);
  NodeOutput *output_socket = this->get_output_socket(0);
  ConvolutionFilterOperation *operation = nullptr;

  switch (this->get_bnode()->custom1) {
    case CMP_FILT_SOFT:
      operation = new ConvolutionFilterOperation();
      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);
      break;
    case CMP_FILT_SHARP_BOX:
      operation = new ConvolutionFilterOperation();
      operation->set3x3Filter(-1, -1, -1, -1, 9, -1, -1, -1, -1);
      break;
    case CMP_FILT_LAPLACE:
      operation = new ConvolutionEdgeFilterOperation();
      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);
      break;
    case CMP_FILT_SOBEL:
      operation = new ConvolutionEdgeFilterOperation();
      operation->set3x3Filter(1, 2, 1, 0, 0, 0, -1, -2, -1);
      break;
    case CMP_FILT_PREWITT:
      operation = new ConvolutionEdgeFilterOperation();
      operation->set3x3Filter(1, 1, 1, 0, 0, 0, -1, -1, -1);
      break;
    case CMP_FILT_KIRSCH:
      operation = new ConvolutionEdgeFilterOperation();
      operation->set3x3Filter(5, 5, 5, -3, -3, -3, -2, -2, -2);
      break;
    case CMP_FILT_SHADOW:
      operation = new ConvolutionFilterOperation();
      operation->set3x3Filter(1, 2, 1, 0, 1, 0, -1, -2, -1);
      break;
    case CMP_FILT_SHARP_DIAMOND:
      operation = new ConvolutionFilterOperation();
      operation->set3x3Filter(0, -1, 0, -1, 5, -1, 0, -1, 0);
      break;
    default:
      operation = new ConvolutionFilterOperation();
      operation->set3x3Filter(0, 0, 0, 0, 1, 0, 0, 0, 0);
      break;
  }
  converter.add_operation(operation);

  converter.map_input_socket(input_image_socket, operation->get_input_socket(0));
  converter.map_input_socket(input_socket, operation->get_input_socket(1));
  converter.map_output_socket(output_socket, operation->get_output_socket());

  converter.add_preview(operation->get_output_socket(0));
}

}  // namespace blender::compositor