Blender
V4.3
source
blender
compositor
operations
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
5
#include "
COM_ChannelMatteOperation.h
"
6
7
namespace
blender::compositor
{
8
9
ChannelMatteOperation::ChannelMatteOperation
()
10
{
11
add_input_socket
(
DataType::Color
);
12
add_output_socket
(
DataType::Value
);
13
14
flags_
.can_be_constant =
true
;
15
}
16
17
void
ChannelMatteOperation::init_execution
()
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
63
void
ChannelMatteOperation::update_memory_buffer_partial
(
MemoryBuffer
*
output
,
64
const
rcti
&area,
65
Span<MemoryBuffer *>
inputs
)
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
COM_ChannelMatteOperation.h
output
#define output
blender::Span
Definition
BLI_span.hh:75
blender::compositor::ChannelMatteOperation::init_execution
void init_execution() override
Definition
COM_ChannelMatteOperation.cc:17
blender::compositor::ChannelMatteOperation::update_memory_buffer_partial
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
Definition
COM_ChannelMatteOperation.cc:63
blender::compositor::ChannelMatteOperation::ChannelMatteOperation
ChannelMatteOperation()
Definition
COM_ChannelMatteOperation.cc:9
blender::compositor::MemoryBuffer
a MemoryBuffer contains access to the data
Definition
COM_MemoryBuffer.h:35
blender::compositor::NodeOperation::add_output_socket
void add_output_socket(DataType datatype)
Definition
COM_NodeOperation.cc:102
blender::compositor::NodeOperation::flags_
NodeOperationFlags flags_
Definition
COM_NodeOperation.h:295
blender::compositor::NodeOperation::add_input_socket
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
Definition
COM_NodeOperation.cc:97
blender::compositor::DataType::Value
@ Value
Value data type.
Definition
COM_defines.h:23
blender::compositor::DataType::Color
@ Color
Color data type.
Definition
COM_defines.h:27
blender::color
Definition
BLI_color_mix.hh:21
blender::compositor
Definition
COM_JumpFloodingAlgorithm.cc:20
blender::compositor::BuffersIterator
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
Definition
COM_BuffersIterator.h:179
inputs
static blender::bke::bNodeSocketTemplate inputs[]
Definition
node_texture_at.cc:11
rcti
Definition
DNA_vec_types.h:68
Generated on Sat Oct 4 2025 05:32:23 for Blender by
doxygen
1.14.0