Blender V5.0
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
8
9#include "BLI_math_matrix.hh"
10
11#include "DNA_node_types.h"
12
13#include "RNA_enum_types.hh"
14
15#include "COM_domain.hh"
16#include "COM_node_operation.hh"
17
19
21
23{
24 b.use_custom_socket_order();
25 b.allow_any_socket_order();
26
27 b.add_input<decl::Color>("Image")
28 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
29 .hide_value()
31 .structure_type(StructureType::Dynamic);
32 b.add_output<decl::Color>("Image").structure_type(StructureType::Dynamic).align_with_previous();
33
34 b.add_input<decl::Float>("X").default_value(0.0f).min(-10000.0f).max(10000.0f);
35 b.add_input<decl::Float>("Y").default_value(0.0f).min(-10000.0f).max(10000.0f);
36
37 PanelDeclarationBuilder &sampling_panel = b.add_panel("Sampling").default_closed(true);
38 sampling_panel.add_input<decl::Menu>("Interpolation")
42 .description("Interpolation method");
43 sampling_panel.add_input<decl::Menu>("Extension X")
44 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
47 .description("The extension mode applied to the X axis");
48 sampling_panel.add_input<decl::Menu>("Extension Y")
49 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
52 .description("The extension mode applied to the Y axis");
53}
54
55static void node_composit_init_translate(bNodeTree * /*ntree*/, bNode *node)
56{
57 /* Unused, kept for forward compatibility. */
59 node->storage = data;
60}
61
62using namespace blender::compositor;
63
65 public:
67
68 void execute() override
69 {
70 const Result &input = this->get_input("Image");
71
72 float x = this->get_input("X").get_single_value_default(0.0f);
73 float y = this->get_input("Y").get_single_value_default(0.0f);
74 const float2 translation = float2(x, y);
75
76 Result &output = this->get_result("Image");
77 output.share_data(input);
78 output.transform(math::from_location<float3x3>(translation));
79 output.get_realization_options().interpolation = this->get_interpolation();
82 }
83
85 {
86 const Result &input = this->get_input("Interpolation");
87 const MenuValue default_menu_value = MenuValue(CMP_NODE_INTERPOLATION_BILINEAR);
88 const MenuValue menu_value = input.get_single_value_default(default_menu_value);
89 const CMPNodeInterpolation interpolation = static_cast<CMPNodeInterpolation>(menu_value.value);
90 switch (interpolation) {
98 }
99
101 }
102
104 {
105 const Result &input = this->get_input("Extension X");
106 const MenuValue default_menu_value = MenuValue(CMP_NODE_EXTENSION_MODE_CLIP);
107 const MenuValue menu_value = input.get_single_value_default(default_menu_value);
108 const CMPExtensionMode extension_x = static_cast<CMPExtensionMode>(menu_value.value);
109 switch (extension_x) {
111 return ExtensionMode::Clip;
116 }
117
118 return ExtensionMode::Clip;
119 }
120
122 {
123 const Result &input = this->get_input("Extension Y");
124 const MenuValue default_menu_value = MenuValue(CMP_NODE_EXTENSION_MODE_CLIP);
125 const MenuValue menu_value = input.get_single_value_default(default_menu_value);
126 const CMPExtensionMode extension_y = static_cast<CMPExtensionMode>(menu_value.value);
127 switch (extension_y) {
129 return ExtensionMode::Clip;
134 }
135
136 return ExtensionMode::Clip;
137 }
138};
139
141{
142 return new TranslateOperation(context, node);
143}
144
145} // namespace blender::nodes::node_composite_translate_cc
146
148{
150
151 static blender::bke::bNodeType ntype;
152
153 cmp_node_type_base(&ntype, "CompositorNodeTranslate", CMP_NODE_TRANSLATE);
154 ntype.ui_name = "Translate";
155 ntype.ui_description = "Offset an image";
156 ntype.enum_name_legacy = "TRANSLATE";
158 ntype.declare = file_ns::cmp_node_translate_declare;
159 ntype.initfunc = file_ns::node_composit_init_translate;
161 ntype, "NodeTranslateData", node_free_standard_storage, node_copy_standard_storage);
162 ntype.get_compositor_operation = file_ns::get_compositor_operation;
163
165}
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:455
#define CMP_NODE_TRANSLATE
CMPNodeInterpolation
@ CMP_NODE_INTERPOLATION_NEAREST
@ CMP_NODE_INTERPOLATION_BILINEAR
@ CMP_NODE_INTERPOLATION_BICUBIC
@ CMP_NODE_INTERPOLATION_ANISOTROPIC
CMPExtensionMode
@ CMP_NODE_EXTENSION_MODE_EXTEND
@ CMP_NODE_EXTENSION_MODE_CLIP
@ CMP_NODE_EXTENSION_MODE_REPEAT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
BMesh const char void * data
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:39
Result & get_input(StringRef identifier) const
Definition operation.cc:138
void share_data(const Result &source)
Definition result.cc:523
RealizationOptions & get_realization_options()
Definition result.cc:630
T get_single_value_default(const T &default_value) const
DeclType::Builder & add_input(StringRef name, StringRef identifier="")
const CompositorInputRealizationMode & compositor_realization_mode() const
#define input
#define output
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:5414
MatT from_location(const typename MatT::loc_type &location)
static void node_composit_init_translate(bNodeTree *, bNode *node)
static void cmp_node_translate_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
VecBase< float, 2 > float2
static void register_node_type_cmp_translate()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
const EnumPropertyItem rna_enum_node_compositor_extension_items[]
const EnumPropertyItem rna_enum_node_compositor_interpolation_items[]
void * storage
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
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362