Blender V4.3
COM_DifferenceMatteOperation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7namespace blender::compositor {
8
17
19 const rcti &area,
21{
22 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
23 const float *color1 = it.in(0);
24 const float *color2 = it.in(1);
25
26 float difference = (fabsf(color2[0] - color1[0]) + fabsf(color2[1] - color1[1]) +
27 fabsf(color2[2] - color1[2]));
28
29 /* Average together the distances. */
30 difference = difference / 3.0f;
31
32 const float tolerance = settings_->t1;
33 const float falloff = settings_->t2;
34
35 /* Make 100% transparent. */
36 if (difference <= tolerance) {
37 it.out[0] = 0.0f;
38 }
39 /* In the falloff region, make partially transparent. */
40 else if (difference <= falloff + tolerance) {
41 difference = difference - tolerance;
42 const float alpha = difference / falloff;
43 /* Only change if more transparent than before. */
44 if (alpha < color1[3]) {
45 it.out[0] = alpha;
46 }
47 else { /* Leave as before. */
48 it.out[0] = color1[3];
49 }
50 }
51 else {
52 /* Foreground object. */
53 it.out[0] = color1[3];
54 }
55 }
56}
57
58} // namespace blender::compositor
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data
void add_output_socket(DataType datatype)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
#define fabsf(x)
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator