Blender V4.3
COM_ConvolutionEdgeFilterOperation.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
10 const rcti &area,
12{
13 const MemoryBuffer *image = inputs[IMAGE_INPUT_INDEX];
14 const int last_x = get_width() - 1;
15 const int last_y = get_height() - 1;
16 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
17 const int left_offset = (it.x == 0) ? 0 : -image->elem_stride;
18 const int right_offset = (it.x == last_x) ? 0 : image->elem_stride;
19 const int down_offset = (it.y == 0) ? 0 : -image->row_stride;
20 const int up_offset = (it.y == last_y) ? 0 : image->row_stride;
21
22 const float *center_color = it.in(IMAGE_INPUT_INDEX);
23 float res1[4] = {0};
24 float res2[4] = {0};
25
26 const float *color = center_color + down_offset + left_offset;
27 madd_v3_v3fl(res1, color, filter_[0]);
28 copy_v3_v3(res2, res1);
29
30 color = center_color + down_offset;
31 madd_v3_v3fl(res1, color, filter_[1]);
32 madd_v3_v3fl(res2, color, filter_[3]);
33
34 color = center_color + down_offset + right_offset;
35 madd_v3_v3fl(res1, color, filter_[2]);
36 madd_v3_v3fl(res2, color, filter_[6]);
37
38 color = center_color + left_offset;
39 madd_v3_v3fl(res1, color, filter_[3]);
40 madd_v3_v3fl(res2, color, filter_[1]);
41
42 {
43 float rgb_filtered[3];
44 mul_v3_v3fl(rgb_filtered, center_color, filter_[4]);
45 add_v3_v3(res1, rgb_filtered);
46 add_v3_v3(res2, rgb_filtered);
47 }
48
49 color = center_color + right_offset;
50 madd_v3_v3fl(res1, color, filter_[5]);
51 madd_v3_v3fl(res2, color, filter_[7]);
52
53 color = center_color + up_offset + left_offset;
54 madd_v3_v3fl(res1, color, filter_[6]);
55 madd_v3_v3fl(res2, color, filter_[2]);
56
57 color = center_color + up_offset;
58 madd_v3_v3fl(res1, color, filter_[7]);
59 madd_v3_v3fl(res2, color, filter_[5]);
60
61 {
62 color = center_color + up_offset + right_offset;
63 float rgb_filtered[3];
64 mul_v3_v3fl(rgb_filtered, color, filter_[8]);
65 add_v3_v3(res1, rgb_filtered);
66 add_v3_v3(res2, rgb_filtered);
67 }
68
69 it.out[0] = sqrt(res1[0] * res1[0] + res2[0] * res2[0]);
70 it.out[1] = sqrt(res1[1] * res1[1] + res2[1] * res2[1]);
71 it.out[2] = sqrt(res1[2] * res1[2] + res2[2] * res2[2]);
72
73 const float factor = *it.in(FACTOR_INPUT_INDEX);
74 const float factor_ = 1.0f - factor;
75 it.out[0] = it.out[0] * factor + center_color[0] * factor_;
76 it.out[1] = it.out[1] * factor + center_color[1] * factor_;
77 it.out[2] = it.out[2] * factor + center_color[2] * factor_;
78
79 it.out[3] = center_color[3];
80
81 /* Make sure we don't return negative color. */
82 CLAMP4_MIN(it.out, 0.0f);
83 }
84}
85
86} // namespace blender::compositor
sqrt(x)+1/max(0
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
#define CLAMP4_MIN(vec, b)
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator