Blender V5.0
sequencer/intern/modifiers/MOD_mask.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_math_base.h"
10#include "BLI_math_matrix.hh"
11
12#include "BLT_translation.hh"
13
14#include "DNA_scene_types.h"
15#include "DNA_sequence_types.h"
16
17#include "SEQ_modifier.hh"
18#include "SEQ_render.hh"
19#include "SEQ_transform.hh"
20
21#include "UI_interface.hh"
23
24#include "modifier.hh"
25
26namespace blender::seq {
27
29 template<typename ImageT, typename MaskSampler>
30 void apply(ImageT *image, MaskSampler &mask, int image_x, IndexRange y_range)
31 {
32 image += y_range.first() * image_x * 4;
33 for (int64_t y : y_range) {
34 mask.begin_row(y);
35 for ([[maybe_unused]] int64_t x : IndexRange(image_x)) {
36 float m = mask.load_mask_min();
37
38 if constexpr (std::is_same_v<ImageT, uchar>) {
39 /* Byte buffer is straight, so only affect on alpha itself, this is
40 * the only way to alpha-over byte strip after applying mask modifier. */
41 image[3] = uchar(image[3] * m);
42 }
43 else if constexpr (std::is_same_v<ImageT, float>) {
44 /* Float buffers are premultiplied, so need to premul color as well to make it
45 * easy to alpha-over masked strip. */
46 float4 pix(image);
47 pix *= m;
48 *reinterpret_cast<float4 *>(image) = pix;
49 }
50 image += 4;
51 }
52 }
53 }
54};
55
57 StripModifierData * /*smd*/,
58 ImBuf *mask)
59{
60 if (mask == nullptr || (mask->byte_buffer.data == nullptr && mask->float_buffer.data == nullptr))
61 {
62 return;
63 }
64
65 MaskApplyOp op;
66 apply_modifier_op(op, context.image, mask, context.transform);
67
68 /* Image has gained transparency. */
69 context.image->planes = R_IMF_PLANES_RGBA;
70}
71
72static void maskmodifier_panel_draw(const bContext *C, Panel *panel)
73{
74 uiLayout *layout = panel->layout;
76
78}
79
84
86 /*idname*/ "Mask",
87 /*name*/ CTX_N_(BLT_I18NCONTEXT_ID_SEQUENCE, "Mask"),
88 /*struct_name*/ "SequencerMaskModifierData",
89 /*struct_size*/ sizeof(SequencerMaskModifierData),
90 /*init_data*/ nullptr,
91 /*free_data*/ nullptr,
92 /*copy_data*/ nullptr,
93 /*apply*/ maskmodifier_apply,
94 /*panel_register*/ maskmodifier_register,
95 /*blend_write*/ nullptr,
96 /*blend_read*/ nullptr,
97};
98
99}; // namespace blender::seq
unsigned char uchar
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_SEQUENCE
@ R_IMF_PLANES_RGBA
@ eSeqModifierType_Mask
#define C
Definition RandGen.cpp:29
PointerRNA * UI_panel_custom_data_get(const Panel *panel)
long long int int64_t
constexpr int64_t first() const
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void draw_mask_input_type_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr)
static void maskmodifier_register(ARegionType *region_type)
void apply_modifier_op(T &op, ImBuf *ibuf, const ImBuf *mask, const float3x3 &mask_transform)
Definition modifier.hh:263
static void maskmodifier_panel_draw(const bContext *C, Panel *panel)
static void maskmodifier_apply(ModifierApplyContext &context, StripModifierData *, ImBuf *mask)
PanelType * modifier_panel_register(ARegionType *region_type, const eStripModifierType type, PanelDrawFn draw)
StripModifierTypeInfo seqModifierType_Mask
VecBase< float, 4 > float4
struct uiLayout * layout
void apply(ImageT *image, MaskSampler &mask, int image_x, IndexRange y_range)
PointerRNA * ptr
Definition wm_files.cc:4238