Blender V4.3
COM_EllipseMaskOperation.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 EllipseMaskOperation::apply_mask(MemoryBuffer *output,
59 const rcti &area,
61 MaskFunc mask_func)
62{
63 const MemoryBuffer *input_mask = inputs[0];
64 const MemoryBuffer *input_value = inputs[1];
65 const float op_last_x = std::max(this->get_width() - 1.0f, FLT_EPSILON);
66 const float op_last_y = std::max(this->get_height() - 1.0f, FLT_EPSILON);
67 const float half_w = data_->width / 2.0f;
68 const float half_h = data_->height / 2.0f;
69 const float tx = half_w * half_w;
70 const float ty = half_h * half_h;
71 for (int y = area.ymin; y < area.ymax; y++) {
72 const float op_ry = y / op_last_y;
73 const float dy = (op_ry - data_->y) / aspect_ratio_;
74 float *out = output->get_elem(area.xmin, y);
75 const float *mask = input_mask->get_elem(area.xmin, y);
76 const float *value = input_value->get_elem(area.xmin, y);
77 for (int x = area.xmin; x < area.xmax; x++) {
78 const float op_rx = x / op_last_x;
79 const float dx = op_rx - data_->x;
80 const float rx = data_->x + (cosine_ * dx + sine_ * dy);
81 const float ry = data_->y + (-sine_ * dx + cosine_ * dy);
82 float sx = rx - data_->x;
83 sx *= sx;
84 float sy = ry - data_->y;
85 sy *= sy;
86 const bool inside = ((sx / tx) + (sy / ty)) <= (1.0f + FLT_EPSILON);
87 out[0] = mask_func(inside, mask, value);
88
89 mask += input_mask->elem_stride;
90 value += input_value->elem_stride;
91 out += output->elem_stride;
92 }
93 }
94}
95
96} // 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)