Blender V4.3
COM_MaskNode.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "COM_MaskNode.h"
6#include "COM_MaskOperation.h"
8
9namespace blender::compositor {
10
11MaskNode::MaskNode(bNode *editor_node) : Node(editor_node)
12{
13 /* pass */
14}
15
17 const CompositorContext &context) const
18{
19 const RenderData *rd = context.get_render_data();
20 const float render_size_factor = context.get_render_percentage_as_factor();
21
22 NodeOutput *output_mask = this->get_output_socket(0);
23
24 const bNode *editor_node = this->get_bnode();
25 const NodeMask *data = (const NodeMask *)editor_node->storage;
26 Mask *mask = (Mask *)editor_node->id;
27
28 /* Always connect the output image. */
29 MaskOperation *operation = new MaskOperation();
30
31 if (editor_node->custom1 & CMP_NODE_MASK_FLAG_SIZE_FIXED) {
32 operation->set_mask_width(data->size_x);
33 operation->set_mask_height(data->size_y);
34 }
35 else if (editor_node->custom1 & CMP_NODE_MASK_FLAG_SIZE_FIXED_SCENE) {
36 operation->set_mask_width(data->size_x * render_size_factor);
37 operation->set_mask_height(data->size_y * render_size_factor);
38 }
39 else {
40 operation->set_mask_width(rd->xsch * render_size_factor);
41 operation->set_mask_height(rd->ysch * render_size_factor);
42 }
43
44 operation->set_mask(mask);
45 operation->set_framenumber(context.get_framenumber());
46 operation->set_feather(bool(editor_node->custom1 & CMP_NODE_MASK_FLAG_NO_FEATHER) == 0);
47
48 if ((editor_node->custom1 & CMP_NODE_MASK_FLAG_MOTION_BLUR) && (editor_node->custom2 > 1) &&
49 (editor_node->custom3 > FLT_EPSILON))
50 {
51 operation->set_motion_blur_samples(editor_node->custom2);
52 operation->set_motion_blur_shutter(editor_node->custom3);
53 }
54
55 converter.add_operation(operation);
56
57 ScaleFixedSizeOperation *scale_operation = new ScaleFixedSizeOperation();
58 scale_operation->set_variable_size(true);
59 /* Consider aspect ratio from scene. */
60 const int new_height = rd->xasp / rd->yasp * operation->get_mask_height();
61 scale_operation->set_new_height(new_height);
62 scale_operation->set_new_width(operation->get_mask_width());
63 scale_operation->set_is_aspect(false);
64 scale_operation->set_is_crop(false);
65 scale_operation->set_offset(0.0f, 0.0f);
66
67 converter.add_operation(scale_operation);
68 converter.add_link(operation->get_output_socket(0), scale_operation->get_input_socket(0));
69
70 converter.map_output_socket(output_mask, scale_operation->get_output_socket(0));
71}
72
73} // namespace blender::compositor
@ CMP_NODE_MASK_FLAG_SIZE_FIXED
@ CMP_NODE_MASK_FLAG_NO_FEATHER
@ CMP_NODE_MASK_FLAG_SIZE_FIXED_SCENE
@ CMP_NODE_MASK_FLAG_MOTION_BLUR
Overall context of the compositor.
MaskNode(bNode *editor_node)
void convert_to_operations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void set_motion_blur_shutter(float shutter)
void set_framenumber(int frame_number)
void add_link(NodeOperationOutput *from, NodeOperationInput *to)
void map_output_socket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void add_operation(NodeOperation *operation)
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:239
NodeOutput * get_output_socket(unsigned int index=0) const
Definition COM_Node.cc:85
const bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition COM_Node.h:65
int16_t custom1
struct ID * id
void * storage
float custom3
int16_t custom2