Blender V5.3
node_composite_translate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_math_matrix.hh"
6
7#include "DNA_node_types.h"
8
9#include "RNA_enum_types.hh"
10
11#include "COM_domain.hh"
12#include "COM_node_operation.hh"
13
15
17
19{
20 b.use_custom_socket_order();
21 b.allow_any_socket_order();
22
23 b.add_input<decl::Color>("Image"_ustr)
24 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
25 .hide_value()
27 .structure_type(StructureType::Dynamic);
28 b.add_output<decl::Color>("Image"_ustr)
29 .structure_type(StructureType::Dynamic)
30 .align_with_previous();
31
32 b.add_input<decl::Float>("X"_ustr)
33 .default_value(0.0f)
35 .min(-10000.0f)
36 .max(10000.0f);
37 b.add_input<decl::Float>("Y"_ustr)
38 .default_value(0.0f)
40 .min(-10000.0f)
41 .max(10000.0f);
42
43 PanelDeclarationBuilder &sampling_panel = b.add_panel("Sampling"_ustr).default_closed(true);
44 sampling_panel.add_input<decl::Menu>("Interpolation"_ustr)
48 .description("Interpolation method");
49 sampling_panel.add_input<decl::Menu>("Extension X"_ustr)
50 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
53 .description("The extension mode applied to the X axis");
54 sampling_panel.add_input<decl::Menu>("Extension Y"_ustr)
55 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
58 .description("The extension mode applied to the Y axis");
59}
60
61static void node_init(bNodeTree * /*ntree*/, bNode *node)
62{
63 /* Unused, kept for forward compatibility. */
64 NodeTranslateData *data = MEM_new<NodeTranslateData>(__func__);
65 node->storage = data;
66}
67
68using namespace blender::compositor;
69
71 public:
73 {
74 InputDescriptor &image_descriptor = this->get_input_descriptor("Image");
75 image_descriptor.skip_type_conversion = true;
76 }
77
78 void execute() override
79 {
80 const Result &input = this->get_input("Image");
81
82 float x = this->get_input("X").get_single_value_default<float>();
83 float y = this->get_input("Y").get_single_value_default<float>();
84 const float2 translation = float2(x, y);
85
86 Result &output = this->get_result("Image");
87 output.set_type(input.type());
88 output.share_data(input);
89 output.transform(math::from_location<float3x3>(translation));
90 output.get_realization_options().interpolation = this->get_interpolation();
91 output.get_realization_options().extension_x = this->get_extension_mode_x();
92 output.get_realization_options().extension_y = this->get_extension_mode_y();
93 }
94
96 {
97 const CMPNodeInterpolation interpolation = CMPNodeInterpolation(
98 this->get_input("Interpolation").get_single_value_default<MenuValue>().value);
99 switch (interpolation) {
108 }
109
111 }
112
114 {
115 const CMPExtensionMode extension_x = CMPExtensionMode(
116 this->get_input("Extension X").get_single_value_default<MenuValue>().value);
117 switch (extension_x) {
119 return Extension::Clip;
121 return Extension::Repeat;
123 return Extension::Extend;
124 }
125
126 return Extension::Clip;
127 }
128
130 {
131 const CMPExtensionMode extension_y = CMPExtensionMode(
132 this->get_input("Extension Y").get_single_value_default<MenuValue>().value);
133 switch (extension_y) {
135 return Extension::Clip;
137 return Extension::Repeat;
139 return Extension::Extend;
140 }
141
142 return Extension::Clip;
143 }
144};
145
147{
148 return new TranslateOperation(context, node);
149}
150
151static void node_register()
152{
153 static bke::bNodeType ntype;
154
155 cmp_node_type_base(&ntype, "CompositorNodeTranslate"_ustr, CMP_NODE_TRANSLATE);
156 ntype.ui_name = "Translate";
157 ntype.ui_description = "Offset an image";
158 ntype.enum_name_legacy = "TRANSLATE";
160 ntype.declare = node_declare;
161 ntype.initfunc = node_init;
163 ntype, "NodeTranslateData", node_free_standard_storage, node_copy_standard_storage);
165
167}
169
170} // namespace blender::nodes::node_composite_translate_cc
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:486
#define CMP_NODE_TRANSLATE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#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
InputDescriptor & get_input_descriptor(StringRef identifier)
Definition operation.cc:132
static ResultType type(gpu::TextureFormat format)
Definition result.cc:337
DeclType::Builder & add_input(UString name, UString identifier=""_ustr)
const CompositorInputRealizationMode & compositor_realization_mode() const
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
MatT from_location(const typename MatT::loc_type &location)
static void node_declare(NodeDeclarationBuilder &b)
static void node_init(bNodeTree *, bNode *node)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
const EnumPropertyItem rna_enum_node_compositor_extension_items[]
BMesh const char void * data
@ CMP_NODE_EXTENSION_MODE_REPEAT
@ CMP_NODE_EXTENSION_MODE_EXTEND
@ CMP_NODE_EXTENSION_MODE_CLIP
@ CMP_NODE_INTERPOLATION_NEAREST
@ CMP_NODE_INTERPOLATION_BICUBIC
@ CMP_NODE_INTERPOLATION_ANISOTROPIC
@ CMP_NODE_INTERPOLATION_BILINEAR
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
const EnumPropertyItem rna_enum_node_compositor_interpolation_items[]
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
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393