Blender V4.3
COM_DespeckleOperation.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
5#include "MEM_guardedalloc.h"
6
8
9namespace blender::compositor {
10
19
20BLI_INLINE int color_diff(const float a[3], const float b[3], const float threshold)
21{
22 return ((fabsf(a[0] - b[0]) > threshold) || (fabsf(a[1] - b[1]) > threshold) ||
23 (fabsf(a[2] - b[2]) > threshold));
24}
25
27 const rcti &output_area,
28 rcti &r_input_area)
29{
30 switch (input_idx) {
31 case IMAGE_INPUT_INDEX: {
32 const int add_x = 2; //(filter_width_ - 1) / 2 + 1;
33 const int add_y = 2; //(filter_height_ - 1) / 2 + 1;
34 r_input_area.xmin = output_area.xmin - add_x;
35 r_input_area.xmax = output_area.xmax + add_x;
36 r_input_area.ymin = output_area.ymin - add_y;
37 r_input_area.ymax = output_area.ymax + add_y;
38 break;
39 }
40 case FACTOR_INPUT_INDEX: {
41 r_input_area = output_area;
42 break;
43 }
44 }
45}
46
48 const rcti &area,
50{
51 const MemoryBuffer *image = inputs[IMAGE_INPUT_INDEX];
52 const int last_x = get_width() - 1;
53 const int last_y = get_height() - 1;
54 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
55 const int x1 = std::max(it.x - 1, 0);
56 const int x2 = it.x;
57 const int x3 = std::min(it.x + 1, last_x);
58 const int y1 = std::max(it.y - 1, 0);
59 const int y2 = it.y;
60 const int y3 = std::min(it.y + 1, last_y);
61
62 float w = 0.0f;
63 const float *color_org = it.in(IMAGE_INPUT_INDEX);
64 float color_mid[4];
65 float color_mid_ok[4];
66 const float *in1 = nullptr;
67
68#define TOT_DIV_ONE 1.0f
69#define TOT_DIV_CNR float(M_SQRT1_2)
70
71#define WTOT (TOT_DIV_ONE * 4 + TOT_DIV_CNR * 4)
72
73#define COLOR_ADD(fac) \
74 { \
75 madd_v4_v4fl(color_mid, in1, fac); \
76 if (color_diff(in1, color_org, threshold_)) { \
77 w += fac; \
78 madd_v4_v4fl(color_mid_ok, in1, fac); \
79 } \
80 }
81
82 zero_v4(color_mid);
83 zero_v4(color_mid_ok);
84
85 in1 = image->get_elem(x1, y1);
87 in1 = image->get_elem(x2, y1);
89 in1 = image->get_elem(x3, y1);
91 in1 = image->get_elem(x1, y2);
93
94#if 0
95 const float *in2 = image->get_elem(x2, y2);
96 madd_v4_v4fl(color_mid, in2, filter_[4]);
97#endif
98
99 in1 = image->get_elem(x3, y2);
101 in1 = image->get_elem(x1, y3);
103 in1 = image->get_elem(x2, y3);
105 in1 = image->get_elem(x3, y3);
107
108 mul_v4_fl(color_mid, 1.0f / (4.0f + (4.0f * float(M_SQRT1_2))));
109 // mul_v4_fl(color_mid, 1.0f / w);
110
111 if ((w != 0.0f) && ((w / WTOT) > (threshold_neighbor_)) &&
112 color_diff(color_mid, color_org, threshold_))
113 {
114 const float factor = *it.in(FACTOR_INPUT_INDEX);
115 mul_v4_fl(color_mid_ok, 1.0f / w);
116 interp_v4_v4v4(it.out, color_org, color_mid_ok, factor);
117 }
118 else {
119 copy_v4_v4(it.out, color_org);
120 }
121
122#undef TOT_DIV_ONE
123#undef TOT_DIV_CNR
124#undef WTOT
125#undef COLOR_ADD
126 }
127}
128
129} // namespace blender::compositor
#define BLI_INLINE
#define M_SQRT1_2
MINLINE void mul_v4_fl(float r[4], float f)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void interp_v4_v4v4(float r[4], const float a[4], const float b[4], float t)
Definition math_vector.c:45
MINLINE void zero_v4(float r[4])
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
#define COLOR_ADD(fac)
#define TOT_DIV_CNR
#define TOT_DIV_ONE
#define WTOT
Read Guarded memory(de)allocation.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
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
void add_output_socket(DataType datatype)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void set_canvas_input_index(unsigned int index)
set the index of the input socket that will determine the canvas of this operation
local_group_size(16, 16) .push_constant(Type b
#define fabsf(x)
BLI_INLINE int color_diff(const float a[3], const float b[3], const float threshold)
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
DepsgraphFromCollectionIDsFilter filter_
int ymin
int ymax
int xmin
int xmax