2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2021 Blender Foundation. */
|
2021-06-01 10:25:38 +02:00
|
|
|
|
|
|
|
|
#include "COM_BufferOperation.h"
|
|
|
|
|
|
|
|
|
|
namespace blender::compositor {
|
|
|
|
|
|
2021-06-01 12:00:16 +02:00
|
|
|
BufferOperation::BufferOperation(MemoryBuffer *buffer, DataType data_type)
|
2021-06-01 10:25:38 +02:00
|
|
|
{
|
|
|
|
|
buffer_ = buffer;
|
2021-07-05 23:32:19 +02:00
|
|
|
inflated_buffer_ = nullptr;
|
2021-09-28 19:32:49 +02:00
|
|
|
set_canvas(buffer->get_rect());
|
2021-10-13 23:01:15 +02:00
|
|
|
add_output_socket(data_type);
|
2021-10-13 23:01:53 +02:00
|
|
|
flags_.is_constant_operation = buffer_->is_a_single_elem();
|
|
|
|
|
flags_.is_fullframe_operation = false;
|
2021-07-06 16:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const float *BufferOperation::get_constant_elem()
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(buffer_->is_a_single_elem());
|
2021-10-13 23:01:15 +02:00
|
|
|
return buffer_->get_buffer();
|
2021-06-01 10:25:38 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void BufferOperation::init_execution()
|
2021-08-10 15:24:38 +02:00
|
|
|
{
|
|
|
|
|
if (buffer_->is_a_single_elem()) {
|
2021-10-13 23:01:15 +02:00
|
|
|
init_mutex();
|
2021-08-10 15:24:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void *BufferOperation::initialize_tile_data(rcti * /*rect*/)
|
2021-06-01 10:25:38 +02:00
|
|
|
{
|
2021-07-05 23:32:19 +02:00
|
|
|
if (buffer_->is_a_single_elem() == false) {
|
|
|
|
|
return buffer_;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
lock_mutex();
|
2021-07-05 23:32:19 +02:00
|
|
|
if (!inflated_buffer_) {
|
|
|
|
|
inflated_buffer_ = buffer_->inflate();
|
|
|
|
|
}
|
2021-10-13 23:01:15 +02:00
|
|
|
unlock_mutex();
|
2021-07-05 23:32:19 +02:00
|
|
|
return inflated_buffer_;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void BufferOperation::deinit_execution()
|
2021-07-05 23:32:19 +02:00
|
|
|
{
|
2021-08-10 15:24:38 +02:00
|
|
|
if (buffer_->is_a_single_elem()) {
|
2021-10-13 23:01:15 +02:00
|
|
|
deinit_mutex();
|
2021-08-10 15:24:38 +02:00
|
|
|
}
|
2021-07-05 23:32:19 +02:00
|
|
|
delete inflated_buffer_;
|
2021-06-01 10:25:38 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void BufferOperation::execute_pixel_sampled(float output[4],
|
|
|
|
|
float x,
|
|
|
|
|
float y,
|
|
|
|
|
PixelSampler sampler)
|
2021-06-01 10:25:38 +02:00
|
|
|
{
|
|
|
|
|
switch (sampler) {
|
|
|
|
|
case PixelSampler::Nearest:
|
|
|
|
|
buffer_->read(output, x, y);
|
|
|
|
|
break;
|
|
|
|
|
case PixelSampler::Bilinear:
|
|
|
|
|
default:
|
2021-10-13 23:01:15 +02:00
|
|
|
buffer_->read_bilinear(output, x, y);
|
2021-06-01 10:25:38 +02:00
|
|
|
break;
|
|
|
|
|
case PixelSampler::Bicubic:
|
|
|
|
|
/* No bicubic. Same implementation as ReadBufferOperation. */
|
2021-10-13 23:01:15 +02:00
|
|
|
buffer_->read_bilinear(output, x, y);
|
2021-06-01 10:25:38 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void BufferOperation::execute_pixel_filtered(
|
2021-06-01 10:25:38 +02:00
|
|
|
float output[4], float x, float y, float dx[2], float dy[2])
|
|
|
|
|
{
|
|
|
|
|
const float uv[2] = {x, y};
|
|
|
|
|
const float deriv[2][2] = {{dx[0], dx[1]}, {dy[0], dy[1]}};
|
|
|
|
|
buffer_->readEWA(output, uv, deriv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace blender::compositor
|