Blender V4.3
COM_LuminanceMatteOperation.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
8
9namespace blender::compositor {
10
18
20 const rcti &area,
22{
23 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
24 const float *color = it.in(0);
25 const float luminance = IMB_colormanagement_get_luminance(color);
26
27 /* One line thread-friend algorithm:
28 * `it.out[0] = std::min(color[3], std::min(1.0f, std::max(0.0f, ((luminance - low) / (high -
29 * low))));`
30 */
31
32 /* Test range. */
33 const float high = settings_->t1;
34 const float low = settings_->t2;
35 float alpha;
36 if (luminance > high) {
37 alpha = 1.0f;
38 }
39 else if (luminance < low) {
40 alpha = 0.0f;
41 }
42 else { /* Blend. */
43 alpha = (luminance - low) / (high - low);
44 }
45
46 /* Store matte(alpha) value in [0] to go with
47 * COM_SetAlphaMultiplyOperation and the Value output.
48 */
49
50 /* Don't make something that was more transparent less transparent. */
51 it.out[0] = std::min(alpha, color[3]);
52 }
53}
54
55} // namespace blender::compositor
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
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