Blender V4.3
COM_BoxMaskOperation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7namespace blender::compositor {
8
18{
19 const double rad = double(data_->rotation);
20 cosine_ = cos(rad);
21 sine_ = sin(rad);
22 aspect_ratio_ = float(this->get_width()) / this->get_height();
23}
24
26 const rcti &area,
28{
29 MaskFunc mask_func;
30 switch (mask_type_) {
32 mask_func = [](const bool is_inside, const float *mask, const float *value) {
33 return is_inside ? std::max(mask[0], value[0]) : mask[0];
34 };
35 break;
37 mask_func = [](const bool is_inside, const float *mask, const float *value) {
38 return is_inside ? std::clamp(mask[0] - value[0], 0.0f, 1.0f) : mask[0];
39 };
40 break;
42 mask_func = [](const bool is_inside, const float *mask, const float *value) {
43 return is_inside ? mask[0] * value[0] : 0;
44 };
45 break;
47 mask_func = [](const bool is_inside, const float *mask, const float *value) {
48 if (is_inside) {
49 return mask[0] > 0.0f ? 0.0f : value[0];
50 }
51 return mask[0];
52 };
53 break;
54 }
55 apply_mask(output, area, inputs, mask_func);
56}
57
58void BoxMaskOperation::apply_mask(MemoryBuffer *output,
59 const rcti &area,
61 MaskFunc mask_func)
62{
63 const float op_last_x = std::max(this->get_width() - 1.0f, FLT_EPSILON);
64 const float op_last_y = std::max(this->get_height() - 1.0f, FLT_EPSILON);
65 const float half_w = data_->width / 2.0f + FLT_EPSILON;
66 const float half_h = data_->height / 2.0f + FLT_EPSILON;
67 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
68 const float op_ry = it.y / op_last_y;
69 const float dy = (op_ry - data_->y) / aspect_ratio_;
70 const float op_rx = it.x / op_last_x;
71 const float dx = op_rx - data_->x;
72 const float rx = data_->x + (cosine_ * dx + sine_ * dy);
73 const float ry = data_->y + (-sine_ * dx + cosine_ * dy);
74
75 const bool inside = (rx >= data_->x - half_w && rx <= data_->x + half_w &&
76 ry >= data_->y - half_h && ry <= data_->y + half_h);
77 const float *mask = it.in(0);
78 const float *value = it.in(1);
79 *it.out = mask_func(inside, mask, value);
80 }
81}
82
83} // namespace blender::compositor
typedef double(DMatrix)[4][4]
@ CMP_NODE_MASKTYPE_NOT
@ CMP_NODE_MASKTYPE_SUBTRACT
@ CMP_NODE_MASKTYPE_MULTIPLY
@ CMP_NODE_MASKTYPE_ADD
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data
void add_output_socket(DataType datatype)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
draw_view in_light_buf[] float
static bool is_inside(int x, int y, int cols, int rows)
Definition filesel.cc:768
ccl_device_inline float3 cos(float3 v)
ccl_device_inline float4 mask(const int4 mask, const float4 a)
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator