Blender  V3.3
COM_DifferenceMatteOperation.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 
14  input_image1_program_ = nullptr;
15  input_image2_program_ = nullptr;
16  flags_.can_be_constant = true;
17 }
18 
20 {
21  input_image1_program_ = this->get_input_socket_reader(0);
22  input_image2_program_ = this->get_input_socket_reader(1);
23 }
25 {
26  input_image1_program_ = nullptr;
27  input_image2_program_ = nullptr;
28 }
29 
31  float x,
32  float y,
34 {
35  float in_color1[4];
36  float in_color2[4];
37 
38  const float tolerance = settings_->t1;
39  const float falloff = settings_->t2;
40  float difference;
41  float alpha;
42 
43  input_image1_program_->read_sampled(in_color1, x, y, sampler);
44  input_image2_program_->read_sampled(in_color2, x, y, sampler);
45 
46  difference = (fabsf(in_color2[0] - in_color1[0]) + fabsf(in_color2[1] - in_color1[1]) +
47  fabsf(in_color2[2] - in_color1[2]));
48 
49  /* average together the distances */
50  difference = difference / 3.0f;
51 
52  /* make 100% transparent */
53  if (difference <= tolerance) {
54  output[0] = 0.0f;
55  }
56  /* In the falloff region, make partially transparent. */
57  else if (difference <= falloff + tolerance) {
58  difference = difference - tolerance;
59  alpha = difference / falloff;
60  /* Only change if more transparent than before. */
61  if (alpha < in_color1[3]) {
62  output[0] = alpha;
63  }
64  else { /* leave as before */
65  output[0] = in_color1[3];
66  }
67  }
68  else {
69  /* foreground object */
70  output[0] = in_color1[3];
71  }
72 }
73 
75  const rcti &area,
77 {
78  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
79  const float *color1 = it.in(0);
80  const float *color2 = it.in(1);
81 
82  float difference = (fabsf(color2[0] - color1[0]) + fabsf(color2[1] - color1[1]) +
83  fabsf(color2[2] - color1[2]));
84 
85  /* Average together the distances. */
86  difference = difference / 3.0f;
87 
88  const float tolerance = settings_->t1;
89  const float falloff = settings_->t2;
90 
91  /* Make 100% transparent. */
92  if (difference <= tolerance) {
93  it.out[0] = 0.0f;
94  }
95  /* In the falloff region, make partially transparent. */
96  else if (difference <= falloff + tolerance) {
97  difference = difference - tolerance;
98  const float alpha = difference / falloff;
99  /* Only change if more transparent than before. */
100  if (alpha < color1[3]) {
101  it.out[0] = alpha;
102  }
103  else { /* Leave as before. */
104  it.out[0] = color1[3];
105  }
106  }
107  else {
108  /* Foreground object. */
109  it.out[0] = color1[3];
110  }
111  }
112 }
113 
114 } // namespace blender::compositor
_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
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
#define fabsf(x)
Definition: metal/compat.h:219
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static bNodeSocketTemplate inputs[]