Blender  V3.3
COM_Stabilize2dNode.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_Stabilize2dNode.h"
6 #include "COM_RotateOperation.h"
7 #include "COM_ScaleOperation.h"
10 
11 namespace blender::compositor {
12 
13 Stabilize2dNode::Stabilize2dNode(bNode *editor_node) : Node(editor_node)
14 {
15  /* pass */
16 }
17 
19  const CompositorContext &context) const
20 {
21  bNode *editor_node = this->get_bnode();
22  NodeInput *image_input = this->get_input_socket(0);
23  MovieClip *clip = (MovieClip *)editor_node->id;
24  bool invert = (editor_node->custom2 & CMP_NODEFLAG_STABILIZE_INVERSE) != 0;
25  const PixelSampler sampler = (PixelSampler)editor_node->custom1;
26 
31 
32  scale_attribute->set_attribute(MCA_SCALE);
33  scale_attribute->set_framenumber(context.get_framenumber());
34  scale_attribute->set_movie_clip(clip);
35  scale_attribute->set_invert(invert);
36 
37  angle_attribute->set_attribute(MCA_ANGLE);
38  angle_attribute->set_framenumber(context.get_framenumber());
39  angle_attribute->set_movie_clip(clip);
40  angle_attribute->set_invert(invert);
41 
42  x_attribute->set_attribute(MCA_X);
43  x_attribute->set_framenumber(context.get_framenumber());
44  x_attribute->set_movie_clip(clip);
45  x_attribute->set_invert(invert);
46 
47  y_attribute->set_attribute(MCA_Y);
48  y_attribute->set_framenumber(context.get_framenumber());
49  y_attribute->set_movie_clip(clip);
50  y_attribute->set_invert(invert);
51 
52  converter.add_operation(scale_attribute);
53  converter.add_operation(angle_attribute);
54  converter.add_operation(x_attribute);
55  converter.add_operation(y_attribute);
56 
57  switch (context.get_execution_model()) {
59  ScaleRelativeOperation *scale_operation = new ScaleRelativeOperation();
60  scale_operation->set_sampler(sampler);
61  RotateOperation *rotate_operation = new RotateOperation();
62  rotate_operation->set_do_degree2_rad_conversion(false);
63  TranslateOperation *translate_operation = new TranslateOperation();
64  SetSamplerOperation *psoperation = new SetSamplerOperation();
65  psoperation->set_sampler(sampler);
66 
67  converter.add_operation(scale_operation);
68  converter.add_operation(translate_operation);
69  converter.add_operation(rotate_operation);
70  converter.add_operation(psoperation);
71 
72  converter.add_link(scale_attribute->get_output_socket(),
73  scale_operation->get_input_socket(1));
74  converter.add_link(scale_attribute->get_output_socket(),
75  scale_operation->get_input_socket(2));
76 
77  converter.add_link(angle_attribute->get_output_socket(),
78  rotate_operation->get_input_socket(1));
79 
80  converter.add_link(x_attribute->get_output_socket(),
81  translate_operation->get_input_socket(1));
82  converter.add_link(y_attribute->get_output_socket(),
83  translate_operation->get_input_socket(2));
84 
85  converter.map_output_socket(get_output_socket(), psoperation->get_output_socket());
86 
87  if (invert) {
88  /* Translate -> Rotate -> Scale. */
89  converter.map_input_socket(image_input, translate_operation->get_input_socket(0));
90 
91  converter.add_link(translate_operation->get_output_socket(),
92  rotate_operation->get_input_socket(0));
93  converter.add_link(rotate_operation->get_output_socket(),
94  scale_operation->get_input_socket(0));
95 
96  converter.add_link(scale_operation->get_output_socket(), psoperation->get_input_socket(0));
97  }
98  else {
99  /* Scale -> Rotate -> Translate. */
100  converter.map_input_socket(image_input, scale_operation->get_input_socket(0));
101 
102  converter.add_link(scale_operation->get_output_socket(),
103  rotate_operation->get_input_socket(0));
104  converter.add_link(rotate_operation->get_output_socket(),
105  translate_operation->get_input_socket(0));
106 
107  converter.add_link(translate_operation->get_output_socket(),
108  psoperation->get_input_socket(0));
109  }
110  break;
111  }
113  ScaleRelativeOperation *scale_operation = new ScaleRelativeOperation();
114  scale_operation->set_sampler(sampler);
115  RotateOperation *rotate_operation = new RotateOperation();
116  rotate_operation->set_do_degree2_rad_conversion(false);
117  rotate_operation->set_sampler(sampler);
118  TranslateOperation *translate_operation = new TranslateCanvasOperation();
119 
120  converter.add_operation(scale_operation);
121  converter.add_operation(translate_operation);
122  converter.add_operation(rotate_operation);
123 
124  converter.add_link(scale_attribute->get_output_socket(),
125  scale_operation->get_input_socket(1));
126  converter.add_link(scale_attribute->get_output_socket(),
127  scale_operation->get_input_socket(2));
128 
129  converter.add_link(angle_attribute->get_output_socket(),
130  rotate_operation->get_input_socket(1));
131 
132  converter.add_link(x_attribute->get_output_socket(),
133  translate_operation->get_input_socket(1));
134  converter.add_link(y_attribute->get_output_socket(),
135  translate_operation->get_input_socket(2));
136 
137  NodeOperationInput *stabilization_socket = nullptr;
138  if (invert) {
139  /* Translate -> Rotate -> Scale. */
140  stabilization_socket = translate_operation->get_input_socket(0);
141  converter.map_input_socket(image_input, translate_operation->get_input_socket(0));
142 
143  converter.add_link(translate_operation->get_output_socket(),
144  rotate_operation->get_input_socket(0));
145  converter.add_link(rotate_operation->get_output_socket(),
146  scale_operation->get_input_socket(0));
147 
148  converter.map_output_socket(get_output_socket(), scale_operation->get_output_socket());
149  }
150  else {
151  /* Scale -> Rotate -> Translate. */
152  stabilization_socket = scale_operation->get_input_socket(0);
153  converter.map_input_socket(image_input, scale_operation->get_input_socket(0));
154 
155  converter.add_link(scale_operation->get_output_socket(),
156  rotate_operation->get_input_socket(0));
157  converter.add_link(rotate_operation->get_output_socket(),
158  translate_operation->get_input_socket(0));
159 
160  converter.map_output_socket(get_output_socket(), translate_operation->get_output_socket());
161  }
162 
163  x_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket);
164  y_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket);
165  scale_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket);
166  angle_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket);
167  break;
168  }
169  }
170 }
171 
172 } // namespace blender::compositor
@ CMP_NODEFLAG_STABILIZE_INVERSE
void set_sampler(PixelSampler sampler)
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:190
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:84
bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:64
NodeInput * get_input_socket(unsigned int index) const
Definition: COM_Node.cc:89
void set_sampler(PixelSampler sampler)
void convert_to_operations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: invert.h:8
short custom1
struct ID * id
short custom2