Blender V4.3
node_composite_mask.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
9#include "BLI_string_utf8.h"
10
11#include "DNA_mask_types.h"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
16#include "COM_cached_mask.hh"
17#include "COM_node_operation.hh"
18
20
21/* **************** Mask ******************** */
22
24
26
28{
29 b.add_output<decl::Float>("Mask");
30}
31
32static void node_composit_init_mask(bNodeTree * /*ntree*/, bNode *node)
33{
34 NodeMask *data = MEM_cnew<NodeMask>(__func__);
35 data->size_x = data->size_y = 256;
36 node->storage = data;
37
38 node->custom2 = 16; /* samples */
39 node->custom3 = 0.5f; /* shutter */
40}
41
42static void node_mask_label(const bNodeTree * /*ntree*/,
43 const bNode *node,
44 char *label,
45 int label_maxncpy)
46{
47 BLI_strncpy_utf8(label, node->id ? node->id->name + 2 : IFACE_("Mask"), label_maxncpy);
48}
49
51{
52 bNode *node = (bNode *)ptr->data;
53
54 uiTemplateID(layout, C, ptr, "mask", nullptr, nullptr, nullptr);
55 uiItemR(layout, ptr, "use_feather", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
56
57 uiItemR(layout, ptr, "size_source", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
58
60 uiItemR(layout, ptr, "size_x", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
61 uiItemR(layout, ptr, "size_y", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
62 }
63
64 uiItemR(layout, ptr, "use_motion_blur", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
65 if (node->custom1 & CMP_NODE_MASK_FLAG_MOTION_BLUR) {
66 uiItemR(layout, ptr, "motion_blur_samples", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
67 uiItemR(layout, ptr, "motion_blur_shutter", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
68 }
69}
70
71using namespace blender::realtime_compositor;
72
74 public:
76
77 void execute() override
78 {
79 Result &output_mask = get_result("Mask");
80 if (!get_mask() || (!is_fixed_size() && !context().is_valid_compositing_region())) {
81 output_mask.allocate_invalid();
82 return;
83 }
84
85 const Domain domain = compute_domain();
87 context(),
88 get_mask(),
89 domain.size,
94
95 output_mask.wrap_external(cached_mask.texture());
96 }
97
99 {
100 return Domain(compute_size());
101 }
102
104 {
106 return get_size();
107 }
108
111 }
112
114 }
115
117 {
118 return int2(node_storage(bnode()).size_x, node_storage(bnode()).size_y);
119 }
120
122 {
123 if (is_fixed_size()) {
124 return 1.0f;
125 }
126
128 }
129
134
136 {
138 }
139
141 {
142 return use_motion_blur() ? bnode().custom2 : 1;
143 }
144
146 {
147 return bnode().custom3;
148 }
149
151 {
153 }
154
156 {
157 return static_cast<CMPNodeMaskFlags>(bnode().custom1);
158 }
159
161 {
162 return reinterpret_cast<Mask *>(bnode().id);
163 }
164};
165
167{
168 return new MaskOperation(context, node);
169}
170
171} // namespace blender::nodes::node_composite_mask_cc
172
174{
175 namespace file_ns = blender::nodes::node_composite_mask_cc;
176
177 static blender::bke::bNodeType ntype;
178
179 cmp_node_type_base(&ntype, CMP_NODE_MASK, "Mask", NODE_CLASS_INPUT);
180 ntype.declare = file_ns::cmp_node_mask_declare;
181 ntype.draw_buttons = file_ns::node_composit_buts_mask;
182 ntype.initfunc = file_ns::node_composit_init_mask;
183 ntype.labelfunc = file_ns::node_mask_label;
184 ntype.get_compositor_operation = file_ns::get_compositor_operation;
185
188
190}
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define IFACE_(msgid)
CMPNodeMaskFlags
@ 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
void uiTemplateID(uiLayout *layout, const bContext *C, PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop, int filter=UI_TEMPLATE_ID_FILTER_ALL, bool live_icon=false, const char *text=nullptr)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
CachedMask & get(Context &context, Mask *mask, int2 size, float aspect_ratio, bool use_feather, int motion_blur_samples, float motion_blur_shutter)
virtual const RenderData & get_render_data() const =0
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:46
void wrap_external(GPUTexture *texture)
Definition result.cc:321
local_group_size(16, 16) .push_constant(Type b
const char * label
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_composit_buts_mask(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void cmp_node_mask_declare(NodeDeclarationBuilder &b)
static void node_mask_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_composit_init_mask(bNodeTree *, bNode *node)
VecBase< int32_t, 2 > int2
void register_node_type_cmp_mask()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
void * data
Definition RNA_types.hh:42
int16_t custom1
struct ID * id
float custom3
int16_t custom2
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:249
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126