Blender  V3.3
COM_ConvolutionFilterOperation.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 
9 {
13  this->set_canvas_input_index(0);
14  input_operation_ = nullptr;
15  flags_.complex = true;
16 }
18 {
21 }
22 
24  float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9)
25 {
26  filter_[0] = f1;
27  filter_[1] = f2;
28  filter_[2] = f3;
29  filter_[3] = f4;
30  filter_[4] = f5;
31  filter_[5] = f6;
32  filter_[6] = f7;
33  filter_[7] = f8;
34  filter_[8] = f9;
35  filter_height_ = 3;
36  filter_width_ = 3;
37 }
38 
40 {
41  input_operation_ = nullptr;
42  input_value_operation_ = nullptr;
43 }
44 
45 void ConvolutionFilterOperation::execute_pixel(float output[4], int x, int y, void * /*data*/)
46 {
47  float in1[4];
48  float in2[4];
49  int x1 = x - 1;
50  int x2 = x;
51  int x3 = x + 1;
52  int y1 = y - 1;
53  int y2 = y;
54  int y3 = y + 1;
55  CLAMP(x1, 0, get_width() - 1);
56  CLAMP(x2, 0, get_width() - 1);
57  CLAMP(x3, 0, get_width() - 1);
58  CLAMP(y1, 0, get_height() - 1);
59  CLAMP(y2, 0, get_height() - 1);
60  CLAMP(y3, 0, get_height() - 1);
61  float value[4];
62  input_value_operation_->read(value, x2, y2, nullptr);
63  const float mval = 1.0f - value[0];
64 
65  zero_v4(output);
66  input_operation_->read(in1, x1, y1, nullptr);
67  madd_v4_v4fl(output, in1, filter_[0]);
68  input_operation_->read(in1, x2, y1, nullptr);
69  madd_v4_v4fl(output, in1, filter_[1]);
70  input_operation_->read(in1, x3, y1, nullptr);
71  madd_v4_v4fl(output, in1, filter_[2]);
72  input_operation_->read(in1, x1, y2, nullptr);
73  madd_v4_v4fl(output, in1, filter_[3]);
74  input_operation_->read(in2, x2, y2, nullptr);
75  madd_v4_v4fl(output, in2, filter_[4]);
76  input_operation_->read(in1, x3, y2, nullptr);
77  madd_v4_v4fl(output, in1, filter_[5]);
78  input_operation_->read(in1, x1, y3, nullptr);
79  madd_v4_v4fl(output, in1, filter_[6]);
80  input_operation_->read(in1, x2, y3, nullptr);
81  madd_v4_v4fl(output, in1, filter_[7]);
82  input_operation_->read(in1, x3, y3, nullptr);
83  madd_v4_v4fl(output, in1, filter_[8]);
84 
85  output[0] = output[0] * value[0] + in2[0] * mval;
86  output[1] = output[1] * value[0] + in2[1] * mval;
87  output[2] = output[2] * value[0] + in2[2] * mval;
88  output[3] = output[3] * value[0] + in2[3] * mval;
89 
90  /* Make sure we don't return negative color. */
91  output[0] = MAX2(output[0], 0.0f);
92  output[1] = MAX2(output[1], 0.0f);
93  output[2] = MAX2(output[2], 0.0f);
94  output[3] = MAX2(output[3], 0.0f);
95 }
96 
98  rcti *input, ReadBufferOperation *read_operation, rcti *output)
99 {
100  rcti new_input;
101  int addx = (filter_width_ - 1) / 2 + 1;
102  int addy = (filter_height_ - 1) / 2 + 1;
103  new_input.xmax = input->xmax + addx;
104  new_input.xmin = input->xmin - addx;
105  new_input.ymax = input->ymax + addy;
106  new_input.ymin = input->ymin - addy;
107 
108  return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output);
109 }
110 
112  const rcti &output_area,
113  rcti &r_input_area)
114 {
115  switch (input_idx) {
116  case IMAGE_INPUT_INDEX: {
117  const int add_x = (filter_width_ - 1) / 2 + 1;
118  const int add_y = (filter_height_ - 1) / 2 + 1;
119  r_input_area.xmin = output_area.xmin - add_x;
120  r_input_area.xmax = output_area.xmax + add_x;
121  r_input_area.ymin = output_area.ymin - add_y;
122  r_input_area.ymax = output_area.ymax + add_y;
123  break;
124  }
125  case FACTOR_INPUT_INDEX: {
126  r_input_area = output_area;
127  break;
128  }
129  }
130 }
131 
133  const rcti &area,
135 {
137  const int last_x = get_width() - 1;
138  const int last_y = get_height() - 1;
139  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
140  const int left_offset = (it.x == 0) ? 0 : -image->elem_stride;
141  const int right_offset = (it.x == last_x) ? 0 : image->elem_stride;
142  const int down_offset = (it.y == 0) ? 0 : -image->row_stride;
143  const int up_offset = (it.y == last_y) ? 0 : image->row_stride;
144 
145  const float *center_color = it.in(IMAGE_INPUT_INDEX);
146  zero_v4(it.out);
147  madd_v4_v4fl(it.out, center_color + down_offset + left_offset, filter_[0]);
148  madd_v4_v4fl(it.out, center_color + down_offset, filter_[1]);
149  madd_v4_v4fl(it.out, center_color + down_offset + right_offset, filter_[2]);
150  madd_v4_v4fl(it.out, center_color + left_offset, filter_[3]);
151  madd_v4_v4fl(it.out, center_color, filter_[4]);
152  madd_v4_v4fl(it.out, center_color + right_offset, filter_[5]);
153  madd_v4_v4fl(it.out, center_color + up_offset + left_offset, filter_[6]);
154  madd_v4_v4fl(it.out, center_color + up_offset, filter_[7]);
155  madd_v4_v4fl(it.out, center_color + up_offset + right_offset, filter_[8]);
156 
157  const float factor = *it.in(FACTOR_INPUT_INDEX);
158  const float factor_ = 1.0f - factor;
159  it.out[0] = it.out[0] * factor + center_color[0] * factor_;
160  it.out[1] = it.out[1] * factor + center_color[1] * factor_;
161  it.out[2] = it.out[2] * factor + center_color[2] * factor_;
162  it.out[3] = it.out[3] * factor + center_color[3] * factor_;
163 
164  /* Make sure we don't return negative color. */
165  CLAMP4_MIN(it.out, 0.0f);
166  }
167 }
168 
169 } // namespace blender::compositor
MINLINE void zero_v4(float r[4])
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
#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
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) final
Get input operation area being read by this operation on rendering given output area.
void set3x3Filter(float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9)
void execute_pixel(float output[4], int x, int y, void *data) override
calculate a single pixel
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) override
a MemoryBuffer contains access to the data of a chunk
void add_output_socket(DataType datatype)
SocketReader * get_input_socket_reader(unsigned int index)
void read(float result[4], int x, int y, void *chunk_data)
virtual bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output)
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
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
ccl_global KernelShaderEvalInput * input
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static bNodeSocketTemplate inputs[]
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