Blender  V3.3
COM_GaussianAlphaYBlurOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
5 
6 namespace blender::compositor {
7 
10 {
11 }
12 
14 {
15  lock_mutex();
16  if (!sizeavailable_) {
17  update_gauss();
18  }
19  void *buffer = get_input_operation(0)->initialize_tile_data(nullptr);
20  unlock_mutex();
21  return buffer;
22 }
23 
24 /* TODO(manzanilla): to be removed with tiled implementation. */
26 {
28 
29  init_mutex();
30 
32  float rad = max_ff(size_ * data_.sizey, 0.0f);
34 
37  }
38 }
39 
40 /* TODO(manzanilla): to be removed with tiled implementation. */
41 void GaussianAlphaYBlurOperation::update_gauss()
42 {
43  if (gausstab_ == nullptr) {
44  update_size();
45  float rad = max_ff(size_ * data_.sizey, 0.0f);
46  rad = min_ff(rad, MAX_GAUSSTAB_RADIUS);
48 
50  }
51 
52  if (distbuf_inv_ == nullptr) {
53  update_size();
54  float rad = max_ff(size_ * data_.sizey, 0.0f);
56 
58  }
59 }
60 
61 void GaussianAlphaYBlurOperation::execute_pixel(float output[4], int x, int y, void *data)
62 {
63  const bool do_invert = do_subtract_;
64  MemoryBuffer *input_buffer = (MemoryBuffer *)data;
65  const rcti &input_rect = input_buffer->get_rect();
66  float *buffer = input_buffer->get_buffer();
67  int bufferwidth = input_buffer->get_width();
68  int bufferstartx = input_rect.xmin;
69  int bufferstarty = input_rect.ymin;
70 
71  int xmin = max_ii(x, input_rect.xmin);
72  int ymin = max_ii(y - filtersize_, input_rect.ymin);
73  int ymax = min_ii(y + filtersize_ + 1, input_rect.ymax);
74 
75  /* *** this is the main part which is different to 'GaussianYBlurOperation' *** */
76  int step = get_step();
77 
78  /* gauss */
79  float alpha_accum = 0.0f;
80  float multiplier_accum = 0.0f;
81 
82  /* dilate */
83  float value_max = finv_test(
84  buffer[(x) + (y * bufferwidth)],
85  do_invert); /* init with the current color to avoid unneeded lookups */
86  float distfacinv_max = 1.0f; /* 0 to 1 */
87 
88  for (int ny = ymin; ny < ymax; ny += step) {
89  int bufferindex = ((xmin - bufferstartx)) + ((ny - bufferstarty) * bufferwidth);
90 
91  const int index = (ny - y) + filtersize_;
92  float value = finv_test(buffer[bufferindex], do_invert);
93  float multiplier;
94 
95  /* gauss */
96  {
97  multiplier = gausstab_[index];
98  alpha_accum += value * multiplier;
99  multiplier_accum += multiplier;
100  }
101 
102  /* dilate - find most extreme color */
103  if (value > value_max) {
104  multiplier = distbuf_inv_[index];
105  value *= multiplier;
106  if (value > value_max) {
107  value_max = value;
108  distfacinv_max = multiplier;
109  }
110  }
111  }
112 
113  /* blend between the max value and gauss blue - gives nice feather */
114  const float value_blur = alpha_accum / multiplier_accum;
115  const float value_final = (value_max * distfacinv_max) + (value_blur * (1.0f - distfacinv_max));
116  output[0] = finv_test(value_final, do_invert);
117 }
118 
120 {
122 
123  if (gausstab_) {
125  gausstab_ = nullptr;
126  }
127 
128  if (distbuf_inv_) {
130  distbuf_inv_ = nullptr;
131  }
132 
133  deinit_mutex();
134 }
135 
137  rcti *input, ReadBufferOperation *read_operation, rcti *output)
138 {
139  rcti new_input;
140 #if 0 /* until we add size input */
141  rcti size_input;
142  size_input.xmin = 0;
143  size_input.ymin = 0;
144  size_input.xmax = 5;
145  size_input.ymax = 5;
146 
147  NodeOperation *operation = this->get_input_operation(1);
148  if (operation->determine_depending_area_of_interest(&size_input, read_operation, output)) {
149  return true;
150  }
151  else
152 #endif
153  {
154  if (sizeavailable_ && gausstab_ != nullptr) {
155  new_input.xmax = input->xmax;
156  new_input.xmin = input->xmin;
157  new_input.ymax = input->ymax + filtersize_ + 1;
158  new_input.ymin = input->ymin - filtersize_ - 1;
159  }
160  else {
161  new_input.xmax = this->get_width();
162  new_input.xmin = 0;
163  new_input.ymax = this->get_height();
164  new_input.ymin = 0;
165  }
166  return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output);
167  }
168 }
169 
170 } // namespace blender::compositor
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)
#define MAX_GAUSSTAB_RADIUS
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble ny
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
#define Y
Definition: GeomUtils.cpp:200
float * make_gausstab(float rad, int size)
float * make_dist_fac_inverse(float rad, int size, int falloff)
BLI_INLINE float finv_test(const float f, const bool test)
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) override
void execute_pixel(float output[4], int x, int y, void *data) override
a MemoryBuffer contains access to the data of a chunk
const rcti & get_rect() const
get the rect of this MemoryBuffer
const int get_width() const
get the width of this MemoryBuffer
float * get_buffer()
get the data of this MemoryBuffer
NodeOperation contains calculation logic.
NodeOperation * get_input_operation(int index)
virtual bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output)
virtual void * initialize_tile_data(rcti *)
ccl_global float * buffer
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
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