Blender V5.0
node_composite_convolve.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include <cstdint>
6
9
11
13
14enum class KernelDataType : uint8_t {
15 Float = 0,
16 Color = 1,
17};
18
21 "FLOAT",
22 0,
23 N_("Float"),
24 N_("The kernel is a float and will be convolved with all input channels")},
26 "COLOR",
27 0,
28 N_("Color"),
29 N_("The kernel is a color and each channel of the kernel will be convolved with each "
30 "respective channel in the input")},
31 {0, nullptr, 0, nullptr, nullptr},
32};
33
35{
36 b.use_custom_socket_order();
37 b.allow_any_socket_order();
38 b.add_input<decl::Color>("Image").hide_value().structure_type(StructureType::Dynamic);
39 b.add_output<decl::Color>("Image").structure_type(StructureType::Dynamic).align_with_previous();
40
41 b.add_input<decl::Menu>("Kernel Data Type")
42 .default_value(KernelDataType::Float)
43 .static_items(kernel_data_type_items)
45 b.add_input<decl::Float>("Kernel", "Float Kernel")
46 .hide_value()
47 .structure_type(StructureType::Dynamic)
48 .usage_by_single_menu(int(KernelDataType::Float))
49 .compositor_realization_mode(CompositorInputRealizationMode::Transforms);
50 b.add_input<decl::Color>("Kernel", "Color Kernel")
51 .hide_value()
52 .structure_type(StructureType::Dynamic)
53 .usage_by_single_menu(int(KernelDataType::Color))
54 .compositor_realization_mode(CompositorInputRealizationMode::Transforms);
55 b.add_input<decl::Bool>("Normalize Kernel")
56 .default_value(true)
57 .description("Normalizes the kernel such that it integrates to one");
58}
59
60using namespace blender::compositor;
61
63 public:
65
66 void execute() override
67 {
68 const Result &input = this->get_input("Image");
69 const Result &kernel = this->get_kernel_input();
70 Result &output = this->get_result("Image");
71
72 if (input.is_single_value() || kernel.is_single_value()) {
73 output.share_data(input);
74 return;
75 }
76
77 convolve(this->context(), input, kernel, output, this->get_normalize_kernel());
78 }
79
81 {
82 switch (this->get_kernel_data_type()) {
84 return this->get_input("Float Kernel");
86 return this->get_input("Color Kernel");
87 }
88
90 return this->get_input("Float Kernel");
91 }
92
94 {
95 const Result &input = this->get_input("Kernel Data Type");
96 const MenuValue default_menu_value = MenuValue(KernelDataType::Float);
97 const MenuValue menu_value = input.get_single_value_default(default_menu_value);
98 return static_cast<KernelDataType>(menu_value.value);
99 }
100
102 {
103 return this->get_input("Normalize Kernel").get_single_value_default(true);
104 }
105};
106
108{
109 return new ConvolveOperation(context, node);
110}
111
112static void node_register()
113{
114 static blender::bke::bNodeType ntype;
115
116 cmp_node_type_base(&ntype, "CompositorNodeConvolve");
117 ntype.ui_name = "Convolve";
118 ntype.ui_description = "Convolves an image with a kernel";
120 ntype.declare = node_declare;
122
124}
126
127} // namespace blender::nodes::node_composite_convolve_cc
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:451
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define NOD_REGISTER_NODE(REGISTER_FUNC)
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:39
Result & get_input(StringRef identifier) const
Definition operation.cc:138
T get_single_value_default(const T &default_value) const
bool is_single_value() const
Definition result.cc:758
#define input
#define output
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void convolve(Context &context, const Result &input, const Result &kernel, Result &output, const bool normalize_kernel)
static void node_declare(NodeDeclarationBuilder &b)
static const EnumPropertyItem kernel_data_type_items[]
static NodeOperation * get_compositor_operation(Context &context, DNode node)
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:348
NodeDeclareFunction declare
Definition BKE_node.hh:362
#define N_(msgid)