Blender  V3.3
COM_GaussianBlurBaseOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. */
3 
5 
6 namespace blender::compositor {
7 
10 {
11  gausstab_ = nullptr;
12 #ifdef BLI_HAVE_SSE2
13  gausstab_sse_ = nullptr;
14 #endif
15  filtersize_ = 0;
16  rad_ = 0.0f;
17  dimension_ = dim;
18 }
19 
21 {
24  rad_ = max_ff(size_ * this->get_blur_size(dimension_), 0.0f);
27  }
28 }
29 
31 {
35 #ifdef BLI_HAVE_SSE2
36  gausstab_sse_ = BlurBaseOperation::convert_gausstab_sse(gausstab_, filtersize_);
37 #endif
38  }
39 }
40 
42 {
44 
45  if (gausstab_) {
47  gausstab_ = nullptr;
48  }
49 #ifdef BLI_HAVE_SSE2
50  if (gausstab_sse_) {
51  MEM_freeN(gausstab_sse_);
52  gausstab_sse_ = nullptr;
53  }
54 #endif
55 }
56 
58  const rcti &output_area,
59  rcti &r_input_area)
60 {
61  if (input_idx != IMAGE_INPUT_INDEX) {
62  BlurBaseOperation::get_area_of_interest(input_idx, output_area, r_input_area);
63  return;
64  }
65 
66  r_input_area = output_area;
67  switch (dimension_) {
68  case eDimension::X:
69  r_input_area.xmin = output_area.xmin - filtersize_ - 1;
70  r_input_area.xmax = output_area.xmax + filtersize_ + 1;
71  break;
72  case eDimension::Y:
73  r_input_area.ymin = output_area.ymin - filtersize_ - 1;
74  r_input_area.ymax = output_area.ymax + filtersize_ + 1;
75  break;
76  }
77 }
78 
80  const rcti &area,
82 {
84  const rcti &input_rect = input->get_rect();
85  BuffersIterator<float> it = output->iterate_with({input}, area);
86 
87  int min_input_coord = -1;
88  int max_input_coord = -1;
89  int elem_stride = -1;
90  std::function<int()> get_current_coord;
91  switch (dimension_) {
92  case eDimension::X:
93  min_input_coord = input_rect.xmin;
94  max_input_coord = input_rect.xmax;
95  elem_stride = input->elem_stride;
96  get_current_coord = [&] { return it.x; };
97  break;
98  case eDimension::Y:
99  min_input_coord = input_rect.ymin;
100  max_input_coord = input_rect.ymax;
101  elem_stride = input->row_stride;
102  get_current_coord = [&] { return it.y; };
103  break;
104  }
105 
106  for (; !it.is_end(); ++it) {
107  const int coord = get_current_coord();
108  const int coord_min = max_ii(coord - filtersize_, min_input_coord);
109  const int coord_max = min_ii(coord + filtersize_ + 1, max_input_coord);
110 
111  float ATTR_ALIGN(16) color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f};
112  float multiplier_accum = 0.0f;
113 
114  const int step = QualityStepHelper::get_step();
115  const float *in = it.in(0) + ((intptr_t)coord_min - coord) * elem_stride;
116  const int in_stride = elem_stride * step;
117  int gauss_idx = (coord_min - coord) + filtersize_;
118  const int gauss_end = gauss_idx + (coord_max - coord_min);
119 #ifdef BLI_HAVE_SSE2
120  __m128 accum_r = _mm_load_ps(color_accum);
121  for (; gauss_idx < gauss_end; in += in_stride, gauss_idx += step) {
122  __m128 reg_a = _mm_load_ps(in);
123  reg_a = _mm_mul_ps(reg_a, gausstab_sse_[gauss_idx]);
124  accum_r = _mm_add_ps(accum_r, reg_a);
125  multiplier_accum += gausstab_[gauss_idx];
126  }
127  _mm_store_ps(color_accum, accum_r);
128 #else
129  for (; gauss_idx < gauss_end; in += in_stride, gauss_idx += step) {
130  const float multiplier = gausstab_[gauss_idx];
131  madd_v4_v4fl(color_accum, in, multiplier);
132  multiplier_accum += multiplier;
133  }
134 #endif
135  mul_v4_v4fl(it.out, color_accum, 1.0f / multiplier_accum);
136  }
137 }
138 
139 } // namespace blender::compositor
#define ATTR_ALIGN(x)
MINLINE float max_ff(float a, float b)
MINLINE int min_ii(int a, int b)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
#define MAX_GAUSSTAB_RADIUS
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its and Z components Generates normals with round corners and may slow down renders Vector Displace the surface along an arbitrary direction White Return a random value or color based on an input seed Float Map an input float to a curve and outputs a float value Separate Color
float * make_gausstab(float rad, int size)
virtual 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.
virtual 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 of a chunk
DataType
possible data types for sockets
Definition: COM_defines.h:30
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
ccl_device_inline float3 ceil(const float3 &a)
Definition: math_float3.h:363
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static bNodeSocketTemplate inputs[]
_W64 int intptr_t
Definition: stdint.h:118
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xmax
Definition: DNA_vec_types.h:63