Blender V5.3
node_composite_transform.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "MEM_guardedalloc.h"
6
8#include "BLI_math_matrix.hh"
9
10#include "DNA_node_types.h"
11
12#include "RNA_enum_types.hh"
13
14#include "BKE_node.hh"
15
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"_ustr)
28 .default_value({0.8f, 0.8f, 0.8f, 1.0f})
29 .hide_value()
31 .structure_type(StructureType::Dynamic);
32 b.add_output<decl::Color>("Image"_ustr)
33 .structure_type(StructureType::Dynamic)
34 .align_with_previous();
35
36 b.add_input<decl::Float>("X"_ustr)
37 .default_value(0.0f)
39 .min(-10000.0f)
40 .max(10000.0f);
41 b.add_input<decl::Float>("Y"_ustr)
42 .default_value(0.0f)
44 .min(-10000.0f)
45 .max(10000.0f);
46 b.add_input<decl::Float>("Angle"_ustr)
47 .default_value(0.0f)
48 .min(-10000.0f)
49 .max(10000.0f)
51 b.add_input<decl::Float>("Scale"_ustr).default_value(1.0f).min(0.0001f).max(CMP_SCALE_MAX);
52
53 PanelDeclarationBuilder &sampling_panel = b.add_panel("Sampling"_ustr).default_closed(true);
54 sampling_panel.add_input<decl::Menu>("Interpolation"_ustr)
58 .description("Interpolation method");
59 sampling_panel.add_input<decl::Menu>("Extension X"_ustr)
60 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
63 .description("The extension mode applied to the X axis");
64 sampling_panel.add_input<decl::Menu>("Extension Y"_ustr)
65 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
68 .description("The extension mode applied to the Y axis");
69}
70
71static void node_init(bNodeTree * /*ntree*/, bNode *node)
72{
73 /* Unused, kept for forward compatibility. */
74 NodeTransformData *data = MEM_new<NodeTransformData>(__func__);
75 node->storage = data;
76}
77
78using namespace blender::compositor;
79
81 public:
83 {
84 InputDescriptor &image_descriptor = this->get_input_descriptor("Image");
85 image_descriptor.skip_type_conversion = true;
86 }
87
88 void execute() override
89 {
90 const float2 translation = float2(this->get_input("X").get_single_value_default<float>(),
91 this->get_input("Y").get_single_value_default<float>());
92 const math::AngleRadian rotation = this->get_input("Angle").get_single_value_default<float>();
93 const float2 scale = float2(this->get_input("Scale").get_single_value_default<float>());
94 const float3x3 transformation = math::from_loc_rot_scale<float3x3>(
95 translation, rotation, scale);
96
97 const Result &input = this->get_input("Image");
98 Result &output = this->get_result("Image");
99 output.set_type(input.type());
100 output.share_data(input);
101 output.transform(transformation);
102 output.get_realization_options().interpolation = this->get_interpolation();
103 output.get_realization_options().extension_x = this->get_extension_mode_x();
104 output.get_realization_options().extension_y = this->get_extension_mode_y();
105 }
106
108 {
109 const CMPNodeInterpolation interpolation = CMPNodeInterpolation(
110 this->get_input("Interpolation").get_single_value_default<MenuValue>().value);
111 switch (interpolation) {
120 }
121
123 }
124
126 {
127 const CMPExtensionMode extension_x = CMPExtensionMode(
128 this->get_input("Extension X").get_single_value_default<MenuValue>().value);
129 switch (extension_x) {
131 return Extension::Clip;
133 return Extension::Repeat;
135 return Extension::Extend;
136 }
137
138 return Extension::Clip;
139 }
140
142 {
143 const CMPExtensionMode extension_y = CMPExtensionMode(
144 this->get_input("Extension Y").get_single_value_default<MenuValue>().value);
145 switch (extension_y) {
147 return Extension::Clip;
149 return Extension::Repeat;
151 return Extension::Extend;
152 }
153
154 return Extension::Clip;
155 }
156};
157
159{
160 return new TransformOperation(context, node);
161}
162
163static void node_register()
164{
165 static bke::bNodeType ntype;
166
167 cmp_node_type_base(&ntype, "CompositorNodeTransform"_ustr, CMP_NODE_TRANSFORM);
168 ntype.ui_name = "Transform";
169 ntype.ui_description = "Scale, translate and rotate an image";
170 ntype.enum_name_legacy = "TRANSFORM";
172 ntype.declare = node_declare;
174 ntype.initfunc = node_init;
176 ntype, "NodeTransformData", node_free_standard_storage, node_copy_standard_storage);
177
179}
181
182} // namespace blender::nodes::node_composite_transform_cc
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:486
#define CMP_NODE_TRANSFORM
Read Blender memory allocation and freeing.
#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
float3x3 scale(float3x3 mat, float2 scale)
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
AngleRadianBase< float > AngleRadian
MatT from_loc_rot_scale(const typename MatT::loc_type &location, const RotationT &rotation, const VecBase< typename MatT::base_type, ScaleDim > &scale)
static void node_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void node_init(bNodeTree *, 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)
#define CMP_SCALE_MAX
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