Blender V4.3
COM_ChannelMatteOperation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7namespace blender::compositor {
8
16
18{
19 limit_range_ = limit_max_ - limit_min_;
20
21 switch (limit_method_) {
22 /* SINGLE */
23 case 0: {
24 /* 123 / RGB / HSV / YUV / YCC */
25 const int matte_channel = matte_channel_ - 1;
26 const int limit_channel = limit_channel_ - 1;
27 ids_[0] = matte_channel;
28 ids_[1] = limit_channel;
29 ids_[2] = limit_channel;
30 break;
31 }
32 /* MAX */
33 case 1: {
34 switch (matte_channel_) {
35 case 1: {
36 ids_[0] = 0;
37 ids_[1] = 1;
38 ids_[2] = 2;
39 break;
40 }
41 case 2: {
42 ids_[0] = 1;
43 ids_[1] = 0;
44 ids_[2] = 2;
45 break;
46 }
47 case 3: {
48 ids_[0] = 2;
49 ids_[1] = 0;
50 ids_[2] = 1;
51 break;
52 }
53 default:
54 break;
55 }
56 break;
57 }
58 default:
59 break;
60 }
61}
62
64 const rcti &area,
66{
67 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
68 const float *color = it.in(0);
69
70 /* Matte operation. */
71 float alpha = color[ids_[0]] - std::max(color[ids_[1]], color[ids_[2]]);
72
73 /* Flip because 0.0 is transparent, not 1.0. */
74 alpha = 1.0f - alpha;
75
76 /* Test range. */
77 if (alpha > limit_max_) {
78 alpha = color[3]; /* Whatever it was prior. */
79 }
80 else if (alpha < limit_min_) {
81 alpha = 0.0f;
82 }
83 else { /* Blend. */
84 alpha = (alpha - limit_min_) / limit_range_;
85 }
86
87 /* Store matte(alpha) value in [0] to go with
88 * COM_SetAlphaMultiplyOperation and the Value output.
89 */
90
91 /* Don't make something that was more transparent less transparent. */
92 *it.out = std::min(alpha, color[3]);
93 }
94}
95
96} // 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)
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
const Set< ID * > & ids_