Blender V5.3
node_composite_rotate.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
6#include "BLI_math_matrix.hh"
7
8#include "DNA_node_types.h"
9
10#include "RNA_enum_types.hh"
11
12#include "BKE_node.hh"
13
14#include "COM_domain.hh"
15#include "COM_node_operation.hh"
16
18
20
22{
23 b.use_custom_socket_order();
24 b.allow_any_socket_order();
25
26 b.add_input<decl::Color>("Image"_ustr)
27 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
28 .hide_value()
30 .structure_type(StructureType::Dynamic);
31 b.add_output<decl::Color>("Image"_ustr)
32 .structure_type(StructureType::Dynamic)
33 .align_with_previous();
34
35 b.add_input<decl::Float>("Angle"_ustr)
36 .default_value(0.0f)
37 .min(-10000.0f)
38 .max(10000.0f)
40
41 PanelDeclarationBuilder &sampling_panel = b.add_panel("Sampling"_ustr).default_closed(true);
42 sampling_panel.add_input<decl::Menu>("Interpolation"_ustr)
46 .description("Interpolation method");
47 sampling_panel.add_input<decl::Menu>("Extension X"_ustr)
48 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
51 .description("The extension mode applied to the X axis");
52 sampling_panel.add_input<decl::Menu>("Extension Y"_ustr)
53 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
56 .description("The extension mode applied to the Y axis");
57}
58
59static void node_init(bNodeTree * /*ntree*/, bNode *node)
60{
61 /* Unused, kept for forward compatibility. */
62 NodeRotateData *data = MEM_new<NodeRotateData>(__func__);
63 node->storage = data;
64}
65
66using namespace blender::compositor;
67
69 public:
71 {
72 InputDescriptor &image_descriptor = this->get_input_descriptor("Image");
73 image_descriptor.skip_type_conversion = true;
74 }
75
76 void execute() override
77 {
78 const math::AngleRadian rotation = this->get_input("Angle").get_single_value_default<float>();
79 const float3x3 transformation = math::from_rotation<float3x3>(rotation);
80
81 const Result &input = this->get_input("Image");
82 Result &output = this->get_result("Image");
83 output.set_type(input.type());
84 output.share_data(input);
85 output.transform(transformation);
86 output.get_realization_options().interpolation = this->get_interpolation();
87 output.get_realization_options().extension_x = this->get_extension_mode_x();
88 output.get_realization_options().extension_y = this->get_extension_mode_y();
89 }
90
92 {
93 const CMPNodeInterpolation interpolation = CMPNodeInterpolation(
94 this->get_input("Interpolation").get_single_value_default<MenuValue>().value);
95 switch (interpolation) {
104 }
105
107 }
108
110 {
111 const CMPExtensionMode extension_x = CMPExtensionMode(
112 this->get_input("Extension X").get_single_value_default<MenuValue>().value);
113 switch (extension_x) {
115 return Extension::Clip;
117 return Extension::Repeat;
119 return Extension::Extend;
120 }
121
122 return Extension::Clip;
123 }
124
126 {
127 const CMPExtensionMode extension_y = CMPExtensionMode(
128 this->get_input("Extension Y").get_single_value_default<MenuValue>().value);
129 switch (extension_y) {
131 return Extension::Clip;
133 return Extension::Repeat;
135 return Extension::Extend;
136 }
137
138 return Extension::Clip;
139 }
140};
141
143{
144 return new RotateOperation(context, node);
145}
146
147static void node_register()
148{
149 static bke::bNodeType ntype;
150
151 cmp_node_type_base(&ntype, "CompositorNodeRotate"_ustr, CMP_NODE_ROTATE);
152 ntype.ui_name = "Rotate";
153 ntype.ui_description = "Rotate image by specified angle";
154 ntype.enum_name_legacy = "ROTATE";
156 ntype.declare = node_declare;
157 ntype.initfunc = node_init;
161
163}
165
166} // namespace blender::nodes::node_composite_rotate_cc
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:486
#define CMP_NODE_ROTATE
#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
AngleRadianBase< float > AngleRadian
MatT from_rotation(const RotationT &rotation)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void node_declare(NodeDeclarationBuilder &b)
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)
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