2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2012 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-06-04 15:49:58 +00:00
|
|
|
|
|
|
|
|
#include "COM_MaskNode.h"
|
|
|
|
|
#include "COM_MaskOperation.h"
|
2023-03-28 12:36:14 +02:00
|
|
|
#include "COM_ScaleOperation.h"
|
2012-06-04 15:49:58 +00:00
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
namespace blender::compositor {
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
MaskNode::MaskNode(bNode *editor_node) : Node(editor_node)
|
2012-06-04 15:49:58 +00:00
|
|
|
{
|
2012-06-15 17:57:39 +00:00
|
|
|
/* pass */
|
2012-06-04 15:49:58 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void MaskNode::convert_to_operations(NodeConverter &converter,
|
|
|
|
|
const CompositorContext &context) const
|
2012-06-04 15:49:58 +00:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
const RenderData *rd = context.get_render_data();
|
|
|
|
|
const float render_size_factor = context.get_render_percentage_as_factor();
|
2012-06-04 15:49:58 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
NodeOutput *output_mask = this->get_output_socket(0);
|
2012-06-04 15:49:58 +00:00
|
|
|
|
2022-08-31 11:49:35 -05:00
|
|
|
const bNode *editor_node = this->get_bnode();
|
|
|
|
|
const NodeMask *data = (const NodeMask *)editor_node->storage;
|
2021-10-13 23:01:15 +02:00
|
|
|
Mask *mask = (Mask *)editor_node->id;
|
2012-06-04 15:49:58 +00:00
|
|
|
|
2021-08-04 13:26:47 +10:00
|
|
|
/* Always connect the output image. */
|
2012-06-04 15:49:58 +00:00
|
|
|
MaskOperation *operation = new MaskOperation();
|
2012-07-26 13:29:38 +00:00
|
|
|
|
2023-05-01 12:04:53 +03:00
|
|
|
if (editor_node->custom1 & CMP_NODE_MASK_FLAG_SIZE_FIXED) {
|
2021-10-13 23:01:15 +02:00
|
|
|
operation->set_mask_width(data->size_x);
|
|
|
|
|
operation->set_mask_height(data->size_y);
|
2012-07-26 13:29:38 +00:00
|
|
|
}
|
2023-05-01 12:04:53 +03:00
|
|
|
else if (editor_node->custom1 & CMP_NODE_MASK_FLAG_SIZE_FIXED_SCENE) {
|
2021-10-13 23:01:15 +02:00
|
|
|
operation->set_mask_width(data->size_x * render_size_factor);
|
|
|
|
|
operation->set_mask_height(data->size_y * render_size_factor);
|
2012-07-26 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-13 23:01:15 +02:00
|
|
|
operation->set_mask_width(rd->xsch * render_size_factor);
|
|
|
|
|
operation->set_mask_height(rd->ysch * render_size_factor);
|
2012-07-26 13:29:38 +00:00
|
|
|
}
|
2012-06-04 15:49:58 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
operation->set_mask(mask);
|
|
|
|
|
operation->set_framenumber(context.get_framenumber());
|
2023-05-01 12:04:53 +03:00
|
|
|
operation->set_feather(bool(editor_node->custom1 & CMP_NODE_MASK_FLAG_NO_FEATHER) == 0);
|
2012-06-04 15:49:58 +00:00
|
|
|
|
2023-05-01 12:04:53 +03:00
|
|
|
if ((editor_node->custom1 & CMP_NODE_MASK_FLAG_MOTION_BLUR) && (editor_node->custom2 > 1) &&
|
2021-10-13 23:01:15 +02:00
|
|
|
(editor_node->custom3 > FLT_EPSILON))
|
|
|
|
|
{
|
|
|
|
|
operation->set_motion_blur_samples(editor_node->custom2);
|
|
|
|
|
operation->set_motion_blur_shutter(editor_node->custom3);
|
2012-07-27 09:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
converter.add_operation(operation);
|
2023-03-28 12:36:14 +02:00
|
|
|
|
|
|
|
|
ScaleFixedSizeOperation *scale_operation = new ScaleFixedSizeOperation();
|
|
|
|
|
scale_operation->set_variable_size(true);
|
|
|
|
|
/* Consider aspect ratio from scene. */
|
|
|
|
|
const int new_height = rd->xasp / rd->yasp * operation->get_mask_height();
|
|
|
|
|
scale_operation->set_new_height(new_height);
|
|
|
|
|
scale_operation->set_new_width(operation->get_mask_width());
|
|
|
|
|
scale_operation->set_is_aspect(false);
|
|
|
|
|
scale_operation->set_is_crop(false);
|
2023-03-30 18:57:22 +02:00
|
|
|
scale_operation->set_offset(0.0f, 0.0f);
|
2023-03-28 12:36:14 +02:00
|
|
|
|
|
|
|
|
converter.add_operation(scale_operation);
|
|
|
|
|
converter.add_link(operation->get_output_socket(0), scale_operation->get_input_socket(0));
|
|
|
|
|
|
|
|
|
|
converter.map_output_socket(output_mask, scale_operation->get_output_socket(0));
|
2012-06-04 15:49:58 +00:00
|
|
|
}
|
2021-03-23 17:12:27 +01:00
|
|
|
|
|
|
|
|
} // namespace blender::compositor
|