Blender V5.3
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_c.hh"
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 "PRF_profile.hh"
18
19#include "SEQ_modifier.hh"
20#include "SEQ_render.hh"
21
22#include "UI_interface.hh"
24
25#include "modifier.hh"
26#include "render.hh"
27
28namespace blender::seq {
29
31 template<typename ImageT, typename MaskSampler>
32 void apply(ImageT *image, MaskSampler &mask, int image_x, IndexRange y_range)
33 {
34 image += y_range.first() * image_x * 4;
35 for (int64_t y : y_range) {
36 mask.begin_row(y);
37 for ([[maybe_unused]] int64_t x : IndexRange(image_x)) {
38 float m = mask.load_mask_min();
39
40 if constexpr (std::is_same_v<ImageT, uchar>) {
41 /* Byte buffer is straight, so only affect on alpha itself, this is
42 * the only way to alpha-over byte strip after applying mask modifier. */
43 image[3] = uchar(image[3] * m);
44 }
45 else if constexpr (std::is_same_v<ImageT, float>) {
46 /* Float buffers are pre-multiplied, so need to pre-multiply color as well to make it
47 * easy to alpha-over masked strip. */
48 float4 pix(image);
49 pix *= m;
50 *reinterpret_cast<float4 *>(image) = pix;
51 }
52 image += 4;
53 }
54 }
55 }
56};
57
59{
61 ImBuf *mask = modifier_render_mask_input(context, *smd);
62 if (mask != nullptr && (mask->byte_data() != nullptr || mask->float_data() != nullptr)) {
63 ensure_ibuf_is_sequencer_space(context.render_data.scene, context.result.image, false);
64
65 MaskApplyOp op;
66 apply_modifier_op(op, context.result.image, mask, context.transform);
67
68 /* Image has gained transparency. */
69 context.result.image->color_mode = ImColorMode::RGBA;
70 }
71
72 if (mask != nullptr) {
74 }
75}
76
77static void maskmodifier_panel_draw(const bContext *C, Panel *panel)
78{
79 ui::Layout &layout = *panel->layout;
81
82 draw_mask_input_type_settings(C, layout, ptr);
83}
84
89
91 /*idname*/ "Mask",
92 /*name*/ CTX_N_(BLT_I18NCONTEXT_ID_SEQUENCE, "Mask"),
93 /*struct_name*/ "SequencerMaskModifierData",
94 /*struct_size*/ sizeof(SequencerMaskModifierData),
95 /*init_data*/ nullptr,
96 /*free_data*/ nullptr,
97 /*copy_data*/ nullptr,
98 /*apply*/ maskmodifier_apply,
99 /*panel_register*/ maskmodifier_register,
100 /*blend_write*/ nullptr,
101 /*blend_read*/ nullptr,
102};
103
104}; // namespace blender::seq
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_SEQUENCE
#define PRF_scope_with_name(ui_name, category)
#define C
Definition RandGen.cpp:29
constexpr int64_t first() const
constexpr IndexRange()=default
ImBuf * modifier_render_mask_input(const ModifierApplyContext &context, const StripModifierData &smd)
void ensure_ibuf_is_sequencer_space(const Scene *scene, ImBuf *ibuf, bool make_float)
Definition render.cc:170
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:277
static void maskmodifier_panel_draw(const bContext *C, Panel *panel)
static void maskmodifier_apply(ModifierApplyContext &context, StripModifierData *smd)
void draw_mask_input_type_settings(const bContext *C, ui::Layout &layout, PointerRNA *ptr)
PanelType * modifier_panel_register(ARegionType *region_type, const eStripModifierType type, PanelDrawFn draw)
StripModifierTypeInfo seqModifierType_Mask
PointerRNA * panel_custom_data_get(const Panel *panel)
__int64 int64_t
Definition BKE_text.h:90
VecBase< float, 4 > float4
void IMB_freeImBuf(ImBuf *ibuf)
unsigned char uchar
Definition BKE_text.h:58
ui::Layout * layout
void apply(ImageT *image, MaskSampler &mask, int image_x, IndexRange y_range)