Blender  V3.3
COM_KeyingBlurOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2012 Blender Foundation. */
3 
5 
6 namespace blender::compositor {
7 
9 {
12 
13  size_ = 0;
15 
16  flags_.complex = true;
17 }
18 
20 {
22 
23  return buffer;
24 }
25 
26 void KeyingBlurOperation::execute_pixel(float output[4], int x, int y, void *data)
27 {
28  MemoryBuffer *input_buffer = (MemoryBuffer *)data;
29  const int buffer_width = input_buffer->get_width();
30  float *buffer = input_buffer->get_buffer();
31  int count = 0;
32  float average = 0.0f;
33 
34  if (axis_ == 0) {
35  const int start = MAX2(0, x - size_ + 1), end = MIN2(buffer_width, x + size_);
36  for (int cx = start; cx < end; cx++) {
37  int buffer_index = (y * buffer_width + cx);
38  average += buffer[buffer_index];
39  count++;
40  }
41  }
42  else {
43  const int start = MAX2(0, y - size_ + 1), end = MIN2(input_buffer->get_height(), y + size_);
44  for (int cy = start; cy < end; cy++) {
45  int buffer_index = (cy * buffer_width + x);
46  average += buffer[buffer_index];
47  count++;
48  }
49  }
50 
51  average /= (float)count;
52 
53  output[0] = average;
54 }
55 
57  ReadBufferOperation *read_operation,
58  rcti *output)
59 {
60  rcti new_input;
61 
62  if (axis_ == BLUR_AXIS_X) {
63  new_input.xmin = input->xmin - size_;
64  new_input.ymin = input->ymin;
65  new_input.xmax = input->xmax + size_;
66  new_input.ymax = input->ymax;
67  }
68  else {
69  new_input.xmin = input->xmin;
70  new_input.ymin = input->ymin - size_;
71  new_input.xmax = input->xmax;
72  new_input.ymax = input->ymax + size_;
73  }
74 
75  return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output);
76 }
77 
79  const rcti &output_area,
80  rcti &r_input_area)
81 {
82  switch (axis_) {
83  case BLUR_AXIS_X:
84  r_input_area.xmin = output_area.xmin - size_;
85  r_input_area.ymin = output_area.ymin;
86  r_input_area.xmax = output_area.xmax + size_;
87  r_input_area.ymax = output_area.ymax;
88  break;
89  case BLUR_AXIS_Y:
90  r_input_area.xmin = output_area.xmin;
91  r_input_area.ymin = output_area.ymin - size_;
92  r_input_area.xmax = output_area.xmax;
93  r_input_area.ymax = output_area.ymax + size_;
94  break;
95  default:
96  BLI_assert_msg(0, "Unknown axis");
97  break;
98  }
99 }
100 
102  const rcti &area,
104 {
105  const MemoryBuffer *input = inputs[0];
106  BuffersIterator<float> it = output->iterate_with(inputs, area);
107 
108  int coord_max;
109  int elem_stride;
110  std::function<int()> get_current_coord;
111  switch (axis_) {
112  case BLUR_AXIS_X:
113  get_current_coord = [&] { return it.x; };
114  coord_max = this->get_width();
115  elem_stride = input->elem_stride;
116  break;
117  case BLUR_AXIS_Y:
118  get_current_coord = [&] { return it.y; };
119  coord_max = this->get_height();
120  elem_stride = input->row_stride;
121  break;
122  }
123 
124  for (; !it.is_end(); ++it) {
125  const int coord = get_current_coord();
126  const int start_coord = MAX2(0, coord - size_ + 1);
127  const int end_coord = MIN2(coord_max, coord + size_);
128  const int count = end_coord - start_coord;
129 
130  float sum = 0.0f;
131  const float *start = it.in(0) + (start_coord - coord) * elem_stride;
132  const float *end = start + count * elem_stride;
133  for (const float *elem = start; elem < end; elem += elem_stride) {
134  sum += *elem;
135  }
136 
137  *it.out = sum / count;
138  }
139 }
140 
141 } // namespace blender::compositor
typedef float(TangentPoint)[2]
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
#define UNUSED(x)
#define MAX2(a, b)
#define MIN2(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 y
static T sum(const btAlignedObjectArray< T > &items)
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) 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.
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
const int get_width() const
get the width of this MemoryBuffer
const int get_height() const
get the height of this MemoryBuffer
float * get_buffer()
get the data of this MemoryBuffer
void add_output_socket(DataType datatype)
NodeOperation * get_input_operation(int index)
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)
virtual void * initialize_tile_data(rcti *)
int count
ccl_global float * buffer
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input
ccl_device_inline float average(const float2 &a)
Definition: math_float2.h:170
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