Blender  V3.3
COM_KeyingDespillOperation.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 {
13 
14  despill_factor_ = 0.5f;
15  color_balance_ = 0.5f;
16 
17  pixel_reader_ = nullptr;
18  screen_reader_ = nullptr;
19  flags_.can_be_constant = true;
20 }
21 
23 {
26 }
27 
29 {
30  pixel_reader_ = nullptr;
31  screen_reader_ = nullptr;
32 }
33 
35  float x,
36  float y,
38 {
39  float pixel_color[4];
40  float screen_color[4];
41 
42  pixel_reader_->read_sampled(pixel_color, x, y, sampler);
43  screen_reader_->read_sampled(screen_color, x, y, sampler);
44 
45  const int screen_primary_channel = max_axis_v3(screen_color);
46  const int other_1 = (screen_primary_channel + 1) % 3;
47  const int other_2 = (screen_primary_channel + 2) % 3;
48 
49  const int min_channel = MIN2(other_1, other_2);
50  const int max_channel = MAX2(other_1, other_2);
51 
52  float average_value, amount;
53 
54  average_value = color_balance_ * pixel_color[min_channel] +
55  (1.0f - color_balance_) * pixel_color[max_channel];
56  amount = (pixel_color[screen_primary_channel] - average_value);
57 
58  copy_v4_v4(output, pixel_color);
59 
60  const float amount_despill = despill_factor_ * amount;
61  if (amount_despill > 0.0f) {
62  output[screen_primary_channel] = pixel_color[screen_primary_channel] - amount_despill;
63  }
64 }
65 
67  const rcti &area,
69 {
70  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
71  const float *pixel_color = it.in(0);
72  const float *screen_color = it.in(1);
73 
74  const int screen_primary_channel = max_axis_v3(screen_color);
75  const int other_1 = (screen_primary_channel + 1) % 3;
76  const int other_2 = (screen_primary_channel + 2) % 3;
77 
78  const int min_channel = MIN2(other_1, other_2);
79  const int max_channel = MAX2(other_1, other_2);
80 
81  const float average_value = color_balance_ * pixel_color[min_channel] +
82  (1.0f - color_balance_) * pixel_color[max_channel];
83  const float amount = (pixel_color[screen_primary_channel] - average_value);
84 
85  copy_v4_v4(it.out, pixel_color);
86 
87  const float amount_despill = despill_factor_ * amount;
88  if (amount_despill > 0.0f) {
89  it.out[screen_primary_channel] = pixel_color[screen_primary_channel] - amount_despill;
90  }
91  }
92 }
93 
94 } // namespace blender::compositor
MINLINE int max_axis_v3(const float vec[3])
MINLINE void copy_v4_v4(float r[4], const float a[4])
#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
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
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_sampled(float result[4], float x, float y, PixelSampler sampler)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
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[]