Files
test/source/blender/compositor/operations/COM_KuwaharaAnisotropicStructureTensorOperation.cc
Aras Pranckevicius f5f7024040 Cleanup: Remove now-unused "tiled" compositor implementation
New ("fullframe") CPU compositor backend is being used now, and all the code
related to "tiled" CPU compositor is just never used anymore. The new backend
is faster, uses less memory, better matches GPU compositor, etc.

TL;DR: 20 thousand lines of code gone.

This commit:
- Removes various bits and pieces related to "tiled" compositor (execution
  groups, one-pixel-at-a-time node processing, read/write buffer operations
  related to node execution groups).
- "GPU" (OpenCL) execution device, that was only used by several nodes of
  the tiled compositor.
  - With that, remove CLEW external library too, since nothing within Blender
    uses OpenCL directly anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/118819
2024-02-28 16:59:16 +01:00

85 lines
3.8 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "COM_KuwaharaAnisotropicStructureTensorOperation.h"
#include "BLI_math_base.hh"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_math_vector_types.hh"
namespace blender::compositor {
KuwaharaAnisotropicStructureTensorOperation::KuwaharaAnisotropicStructureTensorOperation()
{
this->add_input_socket(DataType::Color);
this->add_output_socket(DataType::Color);
this->flags_.can_be_constant = true;
}
/* Computes the structure tensor of the image using a Dirac delta window function as described in
* section "3.2 Local Structure Estimation" of the paper:
*
* Kyprianidis, Jan Eric. "Image and video abstraction by multi-scale anisotropic Kuwahara
* filtering." 2011.
*
* The structure tensor should then be smoothed using a Gaussian function to eliminate high
* frequency details. */
void KuwaharaAnisotropicStructureTensorOperation::update_memory_buffer_partial(
MemoryBuffer *output, const rcti &area, Span<MemoryBuffer *> inputs)
{
using math::max, math::min, math::dot;
MemoryBuffer *image = inputs[0];
const int width = image->get_width();
const int height = image->get_height();
/* The weight kernels of the filter optimized for rotational symmetry described in section
* "3.2.1 Gradient Calculation". */
const float corner_weight = 0.182f;
const float center_weight = 1.0f - 2.0f * corner_weight;
for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
const int x = it.x;
const int y = it.y;
float3 input_color;
float3 x_partial_derivative = float3(0.0f);
input_color = float3(image->get_elem(max(0, x - 1), min(height - 1, y + 1)));
x_partial_derivative += input_color * -corner_weight;
input_color = float3(image->get_elem(max(0, x - 1), y));
x_partial_derivative += input_color * -center_weight;
input_color = float3(image->get_elem(max(0, x - 1), max(0, y - 1)));
x_partial_derivative += input_color * -corner_weight;
input_color = float3(image->get_elem(min(width - 1, x + 1), min(height - 1, y + 1)));
x_partial_derivative += input_color * corner_weight;
input_color = float3(image->get_elem(min(width - 1, x + 1), y));
x_partial_derivative += input_color * center_weight;
input_color = float3(image->get_elem(min(width - 1, x + 1), max(0, y - 1)));
x_partial_derivative += input_color * corner_weight;
float3 y_partial_derivative = float3(0.0f);
input_color = float3(image->get_elem(max(0, x - 1), min(height - 1, y + 1)));
y_partial_derivative += input_color * corner_weight;
input_color = float3(image->get_elem(x, min(height - 1, y + 1)));
y_partial_derivative += input_color * center_weight;
input_color = float3(image->get_elem(min(width - 1, x + 1), min(height - 1, y + 1)));
y_partial_derivative += input_color * corner_weight;
input_color = float3(image->get_elem(max(0, x - 1), max(0, y - 1)));
y_partial_derivative += input_color * -corner_weight;
input_color = float3(image->get_elem(x, max(0, y - 1)));
y_partial_derivative += input_color * -center_weight;
input_color = float3(image->get_elem(min(width - 1, x + 1), max(0, y - 1)));
y_partial_derivative += input_color * -corner_weight;
/* We encode the structure tensor in a float4 using a column major storage order. */
float4 structure_tensor = float4(dot(x_partial_derivative, x_partial_derivative),
dot(x_partial_derivative, y_partial_derivative),
dot(x_partial_derivative, y_partial_derivative),
dot(y_partial_derivative, y_partial_derivative));
copy_v4_v4(it.out, structure_tensor);
}
}
} // namespace blender::compositor