Blender V4.3
COM_Stabilize2dNode.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
11
12namespace blender::compositor {
13
14Stabilize2dNode::Stabilize2dNode(bNode *editor_node) : Node(editor_node)
15{
16 /* pass */
17}
18
20 const CompositorContext &context) const
21{
22 const bNode *editor_node = this->get_bnode();
23 NodeInput *image_input = this->get_input_socket(0);
24 MovieClip *clip = (MovieClip *)editor_node->id;
25 bool invert = (editor_node->custom2 & CMP_NODE_STABILIZE_FLAG_INVERSE) != 0;
26 const PixelSampler sampler = (PixelSampler)editor_node->custom1;
27
32
33 scale_attribute->set_attribute(MCA_SCALE);
34 scale_attribute->set_framenumber(context.get_framenumber());
35 scale_attribute->set_movie_clip(clip);
36 scale_attribute->set_invert(invert);
37
38 angle_attribute->set_attribute(MCA_ANGLE);
39 angle_attribute->set_framenumber(context.get_framenumber());
40 angle_attribute->set_movie_clip(clip);
41 angle_attribute->set_invert(invert);
42
43 x_attribute->set_attribute(MCA_X);
44 x_attribute->set_framenumber(context.get_framenumber());
45 x_attribute->set_movie_clip(clip);
46 x_attribute->set_invert(invert);
47
48 y_attribute->set_attribute(MCA_Y);
49 y_attribute->set_framenumber(context.get_framenumber());
50 y_attribute->set_movie_clip(clip);
51 y_attribute->set_invert(invert);
52
53 converter.add_operation(scale_attribute);
54 converter.add_operation(angle_attribute);
55 converter.add_operation(x_attribute);
56 converter.add_operation(y_attribute);
57
58 ScaleRelativeOperation *scale_operation = new ScaleRelativeOperation();
59 scale_operation->set_sampler(sampler);
60 RotateOperation *rotate_operation = new RotateOperation();
61 rotate_operation->set_do_degree2_rad_conversion(false);
62 rotate_operation->set_sampler(sampler);
63 TranslateOperation *translate_operation = new TranslateCanvasOperation();
64 translate_operation->set_sampler(sampler);
65
66 converter.add_operation(scale_operation);
67 converter.add_operation(translate_operation);
68 converter.add_operation(rotate_operation);
69
70 converter.add_link(scale_attribute->get_output_socket(), scale_operation->get_input_socket(1));
71 converter.add_link(scale_attribute->get_output_socket(), scale_operation->get_input_socket(2));
72
73 converter.add_link(angle_attribute->get_output_socket(), rotate_operation->get_input_socket(1));
74
75 converter.add_link(x_attribute->get_output_socket(), translate_operation->get_input_socket(1));
76 converter.add_link(y_attribute->get_output_socket(), translate_operation->get_input_socket(2));
77
78 NodeOperationInput *stabilization_socket = nullptr;
79 if (invert) {
80 /* Translate -> Rotate -> Scale. */
81 stabilization_socket = translate_operation->get_input_socket(0);
82 converter.map_input_socket(image_input, translate_operation->get_input_socket(0));
83
84 converter.add_link(translate_operation->get_output_socket(),
85 rotate_operation->get_input_socket(0));
86 converter.add_link(rotate_operation->get_output_socket(),
87 scale_operation->get_input_socket(0));
88
89 converter.map_output_socket(get_output_socket(), scale_operation->get_output_socket());
90 }
91 else {
92 /* Scale -> Rotate -> Translate. */
93 stabilization_socket = scale_operation->get_input_socket(0);
94 converter.map_input_socket(image_input, scale_operation->get_input_socket(0));
95
96 converter.add_link(scale_operation->get_output_socket(),
97 rotate_operation->get_input_socket(0));
98 converter.add_link(rotate_operation->get_output_socket(),
99 translate_operation->get_input_socket(0));
100
101 converter.map_output_socket(get_output_socket(), translate_operation->get_output_socket());
102 }
103
104 x_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket);
105 y_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket);
106 scale_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket);
107 angle_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket);
108}
109
110} // namespace blender::compositor
@ CMP_NODE_STABILIZE_FLAG_INVERSE
Overall context of the compositor.
void set_socket_input_resolution_for_stabilization(NodeOperationInput *input_socket)
void add_link(NodeOperationOutput *from, NodeOperationInput *to)
void map_output_socket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void add_operation(NodeOperation *operation)
void map_input_socket(NodeInput *node_socket, NodeOperationInput *operation_socket)
NodeInput are sockets that can receive data/input.
Definition COM_Node.h:191
NodeOperationOutput * get_output_socket(unsigned int index=0)
NodeOperationInput * get_input_socket(unsigned int index)
NodeOutput * get_output_socket(unsigned int index=0) const
Definition COM_Node.cc:85
NodeInput * get_input_socket(unsigned int index) const
Definition COM_Node.cc:90
const bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition COM_Node.h:65
void set_sampler(PixelSampler sampler)
void convert_to_operations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
local_group_size(16, 16) .push_constant(Type local_group_size(16, 16) .push_constant(Type input_tx sampler(1, ImageType::FLOAT_2D, "matte_tx") .image(0
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition invert.h:9
int16_t custom1
struct ID * id
int16_t custom2