Blender V5.3
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"_ustr).hide_value().structure_type(StructureType::Dynamic);
39 b.add_output<decl::Color>("Image"_ustr)
40 .structure_type(StructureType::Dynamic)
41 .align_with_previous();
42
43 b.add_input<decl::Menu>("Kernel Data Type"_ustr)
44 .default_value(KernelDataType::Float)
45 .static_items(kernel_data_type_items)
47 b.add_input<decl::Float>("Kernel"_ustr, "Float Kernel"_ustr)
48 .hide_value()
49 .structure_type(StructureType::Dynamic)
50 .usage_by_single_menu(int(KernelDataType::Float))
51 .compositor_realization_mode(CompositorInputRealizationMode::Transforms);
52 b.add_input<decl::Color>("Kernel"_ustr, "Color Kernel"_ustr)
53 .hide_value()
54 .structure_type(StructureType::Dynamic)
55 .usage_by_single_menu(int(KernelDataType::Color))
56 .compositor_realization_mode(CompositorInputRealizationMode::Transforms);
57 b.add_input<decl::Bool>("Normalize Kernel"_ustr)
58 .default_value(true)
59 .description("Normalizes the kernel such that it integrates to one");
60}
61
62using namespace blender::compositor;
63
65 public:
67
68 void execute() override
69 {
70 const Result &input = this->get_input("Image");
71 const Result &kernel = this->get_kernel_input();
72 Result &output = this->get_result("Image");
73
74 if (input.is_single_value() || kernel.is_single_value()) {
75 output.share_data(input);
76 return;
77 }
78
79 convolve(this->context(), input, kernel, output, this->get_normalize_kernel());
80 }
81
83 {
84 switch (this->get_kernel_data_type()) {
86 return this->get_input("Float Kernel");
88 return this->get_input("Color Kernel");
89 }
90
92 return this->get_input("Float Kernel");
93 }
94
96 {
97 return KernelDataType(
98 this->get_input("Kernel Data Type").get_single_value_default<MenuValue>().value);
99 }
100
102 {
103 return this->get_input("Normalize Kernel").get_single_value_default<bool>();
104 }
105};
106
108{
109 return new ConvolveOperation(context, node);
110}
111
112static void node_register()
113{
114 static bke::bNodeType ntype;
115
116 cmp_node_type_base(&ntype, "CompositorNodeConvolve"_ustr);
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:482
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define BLI_assert_unreachable()
#define output
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Definition operation.cc:40
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
ColorSceneLinear4f< eAlpha::Premultiplied > Color
Definition COM_result.hh:96
void convolve(Context &context, const Result &input, const Result &kernel, Result &output, const bool normalize_kernel)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void node_declare(NodeDeclarationBuilder &b)
static const EnumPropertyItem kernel_data_type_items[]
unsigned char uint8_t
Definition BKE_text.h:79
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
NodeDeclareFunction declare
Definition BKE_node.hh:393
#define N_(msgid)