Blender  V3.3
COM_ConvolutionEdgeFilterOperation.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 
8 void ConvolutionEdgeFilterOperation::execute_pixel(float output[4], int x, int y, void * /*data*/)
9 {
10  float in1[4], in2[4], res1[4] = {0.0}, res2[4] = {0.0};
11 
12  int x1 = x - 1;
13  int x2 = x;
14  int x3 = x + 1;
15  int y1 = y - 1;
16  int y2 = y;
17  int y3 = y + 1;
18  CLAMP(x1, 0, get_width() - 1);
19  CLAMP(x2, 0, get_width() - 1);
20  CLAMP(x3, 0, get_width() - 1);
21  CLAMP(y1, 0, get_height() - 1);
22  CLAMP(y2, 0, get_height() - 1);
23  CLAMP(y3, 0, get_height() - 1);
24 
25  float value[4];
26  input_value_operation_->read(value, x2, y2, nullptr);
27  float mval = 1.0f - value[0];
28 
29  input_operation_->read(in1, x1, y1, nullptr);
30  madd_v3_v3fl(res1, in1, filter_[0]);
31  madd_v3_v3fl(res2, in1, filter_[0]);
32 
33  input_operation_->read(in1, x2, y1, nullptr);
34  madd_v3_v3fl(res1, in1, filter_[1]);
35  madd_v3_v3fl(res2, in1, filter_[3]);
36 
37  input_operation_->read(in1, x3, y1, nullptr);
38  madd_v3_v3fl(res1, in1, filter_[2]);
39  madd_v3_v3fl(res2, in1, filter_[6]);
40 
41  input_operation_->read(in1, x1, y2, nullptr);
42  madd_v3_v3fl(res1, in1, filter_[3]);
43  madd_v3_v3fl(res2, in1, filter_[1]);
44 
45  input_operation_->read(in2, x2, y2, nullptr);
46  madd_v3_v3fl(res1, in2, filter_[4]);
47  madd_v3_v3fl(res2, in2, filter_[4]);
48 
49  input_operation_->read(in1, x3, y2, nullptr);
50  madd_v3_v3fl(res1, in1, filter_[5]);
51  madd_v3_v3fl(res2, in1, filter_[7]);
52 
53  input_operation_->read(in1, x1, y3, nullptr);
54  madd_v3_v3fl(res1, in1, filter_[6]);
55  madd_v3_v3fl(res2, in1, filter_[2]);
56 
57  input_operation_->read(in1, x2, y3, nullptr);
58  madd_v3_v3fl(res1, in1, filter_[7]);
59  madd_v3_v3fl(res2, in1, filter_[5]);
60 
61  input_operation_->read(in1, x3, y3, nullptr);
62  madd_v3_v3fl(res1, in1, filter_[8]);
63  madd_v3_v3fl(res2, in1, filter_[8]);
64 
65  output[0] = sqrt(res1[0] * res1[0] + res2[0] * res2[0]);
66  output[1] = sqrt(res1[1] * res1[1] + res2[1] * res2[1]);
67  output[2] = sqrt(res1[2] * res1[2] + res2[2] * res2[2]);
68 
69  output[0] = output[0] * value[0] + in2[0] * mval;
70  output[1] = output[1] * value[0] + in2[1] * mval;
71  output[2] = output[2] * value[0] + in2[2] * mval;
72 
73  output[3] = in2[3];
74 
75  /* Make sure we don't return negative color. */
76  output[0] = MAX2(output[0], 0.0f);
77  output[1] = MAX2(output[1], 0.0f);
78  output[2] = MAX2(output[2], 0.0f);
79  output[3] = MAX2(output[3], 0.0f);
80 }
81 
83  const rcti &area,
85 {
87  const int last_x = get_width() - 1;
88  const int last_y = get_height() - 1;
89  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
90  const int left_offset = (it.x == 0) ? 0 : -image->elem_stride;
91  const int right_offset = (it.x == last_x) ? 0 : image->elem_stride;
92  const int down_offset = (it.y == 0) ? 0 : -image->row_stride;
93  const int up_offset = (it.y == last_y) ? 0 : image->row_stride;
94 
95  const float *center_color = it.in(IMAGE_INPUT_INDEX);
96  float res1[4] = {0};
97  float res2[4] = {0};
98 
99  const float *color = center_color + down_offset + left_offset;
100  madd_v3_v3fl(res1, color, filter_[0]);
101  copy_v3_v3(res2, res1);
102 
103  color = center_color + down_offset;
104  madd_v3_v3fl(res1, color, filter_[1]);
105  madd_v3_v3fl(res2, color, filter_[3]);
106 
107  color = center_color + down_offset + right_offset;
108  madd_v3_v3fl(res1, color, filter_[2]);
109  madd_v3_v3fl(res2, color, filter_[6]);
110 
111  color = center_color + left_offset;
112  madd_v3_v3fl(res1, color, filter_[3]);
113  madd_v3_v3fl(res2, color, filter_[1]);
114 
115  {
116  float rgb_filtered[3];
117  mul_v3_v3fl(rgb_filtered, center_color, filter_[4]);
118  add_v3_v3(res1, rgb_filtered);
119  add_v3_v3(res2, rgb_filtered);
120  }
121 
122  color = center_color + right_offset;
123  madd_v3_v3fl(res1, color, filter_[5]);
124  madd_v3_v3fl(res2, color, filter_[7]);
125 
126  color = center_color + up_offset + left_offset;
127  madd_v3_v3fl(res1, color, filter_[6]);
128  madd_v3_v3fl(res2, color, filter_[2]);
129 
130  color = center_color + up_offset;
131  madd_v3_v3fl(res1, color, filter_[7]);
132  madd_v3_v3fl(res2, color, filter_[5]);
133 
134  {
135  color = center_color + up_offset + right_offset;
136  float rgb_filtered[3];
137  mul_v3_v3fl(rgb_filtered, color, filter_[8]);
138  add_v3_v3(res1, rgb_filtered);
139  add_v3_v3(res2, rgb_filtered);
140  }
141 
142  it.out[0] = sqrt(res1[0] * res1[0] + res2[0] * res2[0]);
143  it.out[1] = sqrt(res1[1] * res1[1] + res2[1] * res2[1]);
144  it.out[2] = sqrt(res1[2] * res1[2] + res2[2] * res2[2]);
145 
146  const float factor = *it.in(FACTOR_INPUT_INDEX);
147  const float factor_ = 1.0f - factor;
148  it.out[0] = it.out[0] * factor + center_color[0] * factor_;
149  it.out[1] = it.out[1] * factor + center_color[1] * factor_;
150  it.out[2] = it.out[2] * factor + center_color[2] * factor_;
151 
152  it.out[3] = center_color[3];
153 
154  /* Make sure we don't return negative color. */
155  CLAMP4_MIN(it.out, 0.0f);
156  }
157 }
158 
159 } // 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)
#define MAX2(a, b)
_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 GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble y1
_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
_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 GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble x2
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void execute_pixel(float output[4], int x, int y, void *data) override
calculate a single pixel
a MemoryBuffer contains access to the data of a chunk
void read(float result[4], int x, int y, void *chunk_data)
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
ccl_global KernelShaderEvalInput ccl_global float * output
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static bNodeSocketTemplate inputs[]