Blender V4.3
COM_DirectionalBlurOperation.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
15
17{
18 const float angle = data_->angle;
19 const float zoom = data_->zoom;
20 const float spin = data_->spin;
21 const float iterations = data_->iter;
22 const float distance = data_->distance;
23 const float center_x = data_->center_x;
24 const float center_y = data_->center_y;
25 const float width = get_width();
26 const float height = get_height();
27
28 const float a = angle;
29 const float itsc = 1.0f / powf(2.0f, float(iterations));
30 float D;
31
32 D = distance * sqrtf(width * width + height * height);
33 center_x_pix_ = center_x * width;
34 center_y_pix_ = center_y * height;
35
36 tx_ = itsc * D * cosf(a);
37 ty_ = -itsc * D * sinf(a);
38 sc_ = itsc * zoom;
39 rot_ = itsc * spin;
40}
41
43 const rcti & /*output_area*/,
44 rcti &r_input_area)
45{
46 BLI_assert(input_idx == 0);
47 UNUSED_VARS_NDEBUG(input_idx);
48 r_input_area = this->get_canvas();
49}
50
52 const rcti &area,
54{
55 const MemoryBuffer *input = inputs[0];
56 const int iterations = pow(2.0f, data_->iter);
57 for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
58 const int x = it.x;
59 const int y = it.y;
60 float color_accum[4];
61 input->read_elem_bilinear(x, y, color_accum);
62
63 /* Blur pixel. */
64 /* TODO(manzanilla): Many values used on iterations can be calculated beforehand. Create a
65 * table on operation initialization. */
66 float ltx = tx_;
67 float lty = ty_;
68 float lsc = sc_;
69 float lrot = rot_;
70 for (int i = 0; i < iterations; i++) {
71 const float cs = cosf(lrot), ss = sinf(lrot);
72 const float isc = 1.0f / (1.0f + lsc);
73
74 const float v = isc * (y + 0.5f - center_y_pix_) + lty;
75 const float u = isc * (x + 0.5f - center_x_pix_) + ltx;
76
77 float color[4];
78 input->read_elem_bilinear(
79 cs * u + ss * v + center_x_pix_ - 0.5f, cs * v - ss * u + center_y_pix_ - 0.5f, color);
80 add_v4_v4(color_accum, color);
81
82 /* Double transformations. */
83 ltx += tx_;
84 lty += ty_;
85 lrot += rot_;
86 lsc += sc_;
87 }
88
89 mul_v4_v4fl(it.out, color_accum, 1.0f / (iterations + 1));
90 }
91}
92
93} // namespace blender::compositor
#define D
#define BLI_assert(a)
Definition BLI_assert.h:50
MINLINE void add_v4_v4(float r[4], const float a[4])
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
#define UNUSED_VARS_NDEBUG(...)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:125
ATTR_WARN_UNUSED_RESULT const BMVert * v
static SpinLock spin
Definition cachefile.cc:154
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)
pow(value.r - subtrahend, 2.0)") .do_static_compilation(true)
#define sinf(x)
#define cosf(x)
#define powf(x, y)
#define sqrtf(x)
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator