Blender  V3.3
COM_ScaleNode.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_ScaleNode.h"
5 
6 #include "BKE_node.h"
7 #include "COM_ScaleOperation.h"
9 
10 namespace blender::compositor {
11 
12 ScaleNode::ScaleNode(bNode *editor_node) : Node(editor_node)
13 {
14  /* pass */
15 }
16 
18  const CompositorContext &context) const
19 {
20  bNode *bnode = this->get_bnode();
21 
22  NodeInput *input_socket = this->get_input_socket(0);
23  NodeInput *input_xsocket = this->get_input_socket(1);
24  NodeInput *input_ysocket = this->get_input_socket(2);
25  NodeOutput *output_socket = this->get_output_socket(0);
26 
27  switch (bnode->custom1) {
28  case CMP_SCALE_RELATIVE: {
30  converter.add_operation(operation);
31 
32  converter.map_input_socket(input_socket, operation->get_input_socket(0));
33  converter.map_input_socket(input_xsocket, operation->get_input_socket(1));
34  converter.map_input_socket(input_ysocket, operation->get_input_socket(2));
35  converter.map_output_socket(output_socket, operation->get_output_socket(0));
36 
37  operation->set_variable_size(input_xsocket->is_linked() || input_ysocket->is_linked());
38  operation->set_scale_canvas_max_size(context.get_render_size() * 1.5f);
39 
40  break;
41  }
43  SetValueOperation *scale_factor_operation = new SetValueOperation();
44  scale_factor_operation->set_value(context.get_render_percentage_as_factor());
45  converter.add_operation(scale_factor_operation);
46 
48  converter.add_operation(operation);
49 
50  converter.map_input_socket(input_socket, operation->get_input_socket(0));
51  converter.add_link(scale_factor_operation->get_output_socket(),
52  operation->get_input_socket(1));
53  converter.add_link(scale_factor_operation->get_output_socket(),
54  operation->get_input_socket(2));
55  converter.map_output_socket(output_socket, operation->get_output_socket(0));
56 
57  operation->set_variable_size(input_xsocket->is_linked() || input_ysocket->is_linked());
58  operation->set_scale_canvas_max_size(context.get_render_size() * 1.5f);
59 
60  break;
61  }
63  const RenderData *rd = context.get_render_data();
64  const float render_size_factor = context.get_render_percentage_as_factor();
66  /* framing options */
67  operation->set_is_aspect((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_ASPECT) != 0);
68  operation->set_is_crop((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_CROP) != 0);
69  operation->set_offset(bnode->custom3, bnode->custom4);
70  operation->set_new_width(rd->xsch * render_size_factor);
71  operation->set_new_height(rd->ysch * render_size_factor);
72  converter.add_operation(operation);
73 
74  converter.map_input_socket(input_socket, operation->get_input_socket(0));
75  converter.map_output_socket(output_socket, operation->get_output_socket(0));
76 
77  operation->set_variable_size(input_xsocket->is_linked() || input_ysocket->is_linked());
78  operation->set_scale_canvas_max_size(context.get_render_size() * 3.0f);
79 
80  break;
81  }
82  case CMP_SCALE_ABSOLUTE: {
83  /* TODO: what is the use of this one.... perhaps some issues when the ui was updated... */
85  converter.add_operation(operation);
86 
87  converter.map_input_socket(input_socket, operation->get_input_socket(0));
88  converter.map_input_socket(input_xsocket, operation->get_input_socket(1));
89  converter.map_input_socket(input_ysocket, operation->get_input_socket(2));
90  converter.map_output_socket(output_socket, operation->get_output_socket(0));
91 
92  operation->set_variable_size(input_xsocket->is_linked() || input_ysocket->is_linked());
93  operation->set_scale_canvas_max_size(context.get_render_size() * 1.5f);
94 
95  break;
96  }
97  }
98 }
99 
100 } // namespace blender::compositor
#define CMP_SCALE_ABSOLUTE
Definition: BKE_node.h:1317
#define CMP_SCALE_SCENEPERCENT
Definition: BKE_node.h:1318
#define CMP_SCALE_RENDERSIZE_FRAME_CROP
Definition: BKE_node.h:1322
#define CMP_SCALE_RENDERSIZE_FRAME_ASPECT
Definition: BKE_node.h:1321
#define CMP_SCALE_RENDERPERCENT
Definition: BKE_node.h:1319
#define CMP_SCALE_RELATIVE
Definition: BKE_node.h:1316
void set_variable_size(bool variable_size)
Overall context of the compositor.
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 are sockets that can send data/input.
Definition: COM_Node.h:238
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
ScaleNode(bNode *editor_node)
void convert_to_operations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
short custom1
float custom4
short custom2
float custom3