Blender V4.3
COM_DistanceRGBMatteOperation.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
18float DistanceRGBMatteOperation::calculate_distance(const float key[4], const float image[4])
19{
20 return len_v3v3(key, image);
21}
22
24 const rcti &area,
26{
27 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
28 const float *in_image = it.in(0);
29 const float *in_key = it.in(1);
30
31 float distance = this->calculate_distance(in_key, in_image);
32 const float tolerance = settings_->t1;
33 const float falloff = settings_->t2;
34
35 /* Store matte(alpha) value in [0] to go with
36 * COM_SetAlphaMultiplyOperation and the Value output.
37 */
38
39 /* Make 100% transparent. */
40 if (distance < tolerance) {
41 it.out[0] = 0.0f;
42 }
43 /* In the falloff region, make partially transparent. */
44 else if (distance < falloff + tolerance) {
45 distance = distance - tolerance;
46 const float alpha = distance / falloff;
47 /* Only change if more transparent than before. */
48 if (alpha < in_image[3]) {
49 it.out[0] = alpha;
50 }
51 else { /* Leave as before. */
52 it.out[0] = in_image[3];
53 }
54 }
55 else {
56 /* Leave as before. */
57 it.out[0] = in_image[3];
58 }
59 }
60}
61
62} // namespace blender::compositor
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
virtual float calculate_distance(const float key[4], const float image[4])
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)
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator