2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2011 Blender Foundation. */
|
2020-10-22 11:13:34 +02:00
|
|
|
|
2021-01-05 16:16:18 +01:00
|
|
|
#include "COM_SetAlphaMultiplyOperation.h"
|
2020-10-22 11:13:34 +02:00
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
namespace blender::compositor {
|
|
|
|
|
|
2021-01-05 16:16:18 +01:00
|
|
|
SetAlphaMultiplyOperation::SetAlphaMultiplyOperation()
|
2020-10-22 11:13:34 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
this->add_input_socket(DataType::Color);
|
|
|
|
|
this->add_input_socket(DataType::Value);
|
|
|
|
|
this->add_output_socket(DataType::Color);
|
2020-10-22 11:13:34 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
input_color_ = nullptr;
|
|
|
|
|
input_alpha_ = nullptr;
|
2021-10-13 23:01:53 +02:00
|
|
|
flags_.can_be_constant = true;
|
2020-10-22 11:13:34 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void SetAlphaMultiplyOperation::init_execution()
|
2020-10-22 11:13:34 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
input_color_ = get_input_socket_reader(0);
|
|
|
|
|
input_alpha_ = get_input_socket_reader(1);
|
2020-10-22 11:13:34 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void SetAlphaMultiplyOperation::execute_pixel_sampled(float output[4],
|
|
|
|
|
float x,
|
|
|
|
|
float y,
|
|
|
|
|
PixelSampler sampler)
|
2020-10-22 11:13:34 +02:00
|
|
|
{
|
|
|
|
|
float color_input[4];
|
|
|
|
|
float alpha_input[4];
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
input_color_->read_sampled(color_input, x, y, sampler);
|
|
|
|
|
input_alpha_->read_sampled(alpha_input, x, y, sampler);
|
2020-10-22 11:13:34 +02:00
|
|
|
|
|
|
|
|
mul_v4_v4fl(output, color_input, alpha_input[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void SetAlphaMultiplyOperation::deinit_execution()
|
2020-10-22 11:13:34 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
input_color_ = nullptr;
|
|
|
|
|
input_alpha_ = nullptr;
|
2020-10-22 11:13:34 +02:00
|
|
|
}
|
2021-03-23 17:12:27 +01:00
|
|
|
|
2021-08-23 15:28:08 +02:00
|
|
|
void SetAlphaMultiplyOperation::update_memory_buffer_partial(MemoryBuffer *output,
|
|
|
|
|
const rcti &area,
|
|
|
|
|
Span<MemoryBuffer *> inputs)
|
|
|
|
|
{
|
|
|
|
|
for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
|
|
|
|
|
const float *color = it.in(0);
|
|
|
|
|
const float alpha = *it.in(1);
|
|
|
|
|
mul_v4_v4fl(it.out, color, alpha);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
} // namespace blender::compositor
|