Blender V4.3
COM_KeyingClipOperation.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
6
7namespace blender::compositor {
8
24
26 const rcti &output_area,
27 rcti &r_input_area)
28{
29 BLI_assert(input_idx == 0);
30 UNUSED_VARS_NDEBUG(input_idx);
31 r_input_area.xmin = output_area.xmin - kernel_radius_;
32 r_input_area.xmax = output_area.xmax + kernel_radius_;
33 r_input_area.ymin = output_area.ymin - kernel_radius_;
34 r_input_area.ymax = output_area.ymax + kernel_radius_;
35}
36
38 const rcti &area,
40{
41 const MemoryBuffer *input = inputs[0];
42 BuffersIterator<float> it = output->iterate_with(inputs, area);
43
44 const int delta = kernel_radius_;
45 const float tolerance = kernel_tolerance_;
46 const int width = this->get_width();
47 const int height = this->get_height();
48 const int row_stride = input->row_stride;
49 const int elem_stride = input->elem_stride;
50 for (; !it.is_end(); ++it) {
51 const int x = it.x;
52 const int y = it.y;
53
54 const int start_x = std::max(0, x - delta);
55 const int start_y = std::max(0, y - delta);
56 const int end_x = std::min(x + delta, width - 1);
57 const int end_y = std::min(y + delta, height - 1);
58 const int x_len = end_x - start_x + 1;
59 const int y_len = end_y - start_y + 1;
60
61 const int total_count = x_len * y_len;
62 const int threshold_count = ceil(float(total_count) * 0.9f);
63 bool ok = false;
64 if (delta == 0) {
65 ok = true;
66 }
67
68 const float *main_elem = it.in(0);
69 const float value = *main_elem;
70 const float *row = input->get_elem(start_x, start_y);
71 const float *end_row = row + y_len * row_stride;
72 int count = 0;
73 for (; ok == false && row < end_row; row += row_stride) {
74 const float *end_elem = row + x_len * elem_stride;
75 for (const float *elem = row; ok == false && elem < end_elem; elem += elem_stride) {
76 const float current_value = *elem;
77 if (fabsf(current_value - value) < tolerance) {
78 count++;
79 if (count >= threshold_count) {
80 ok = true;
81 }
82 }
83 }
84 }
85
86 if (is_edge_matte_) {
87 *it.out = ok ? 0.0f : 1.0f;
88 }
89 else {
90 if (!ok) {
91 *it.out = value;
92 }
93 else if (value < clip_black_) {
94 *it.out = 0.0f;
95 }
96 else if (value >= clip_white_) {
97 *it.out = 1.0f;
98 }
99 else {
100 *it.out = (value - clip_black_) / (clip_white_ - clip_black_);
101 }
102 }
103 }
104}
105
106} // namespace blender::compositor
#define BLI_assert(a)
Definition BLI_assert.h:50
#define UNUSED_VARS_NDEBUG(...)
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override
Get input operation area being read by this operation on rendering given output area.
a MemoryBuffer contains access to the data
BuffersIterator< float > iterate_with(Span< MemoryBuffer * > inputs)
void add_output_socket(DataType datatype)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
#define fabsf(x)
int count
ccl_device_inline float3 ceil(const float3 a)
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
int ymin
int ymax
int xmin
int xmax