Compositor: Rewrite and optimize Double Edge Mask node #117545
|
@ -9,7 +9,7 @@
|
|||
#include "BLI_math_base.h"
|
||||
#include "BLI_math_base.hh"
|
||||
#include "BLI_math_vector.hh"
|
||||
#include "BLI_math_vector_types.hh"
|
||||
#include "BLI_span.hh"
|
||||
#include "BLI_task.hh"
|
||||
|
||||
#include "COM_JumpFloodingAlgorithm.h"
|
||||
|
@ -29,7 +29,7 @@ int2 initialize_jump_flooding_value(int2 texel, bool is_seed)
|
|||
return encode_jump_flooding_value(texel, is_seed);
|
||||
}
|
||||
|
||||
static int2 load_jump_flooding(Array<int2> &input, int2 texel, int2 size, int2 fallback)
|
||||
static int2 load_jump_flooding(Span<int2> input, int2 texel, int2 size, int2 fallback)
|
||||
{
|
||||
if (texel.x < 0 || texel.x >= size.x || texel.y < 0 || texel.y >= size.y) {
|
||||
return fallback;
|
||||
|
@ -37,7 +37,10 @@ static int2 load_jump_flooding(Array<int2> &input, int2 texel, int2 size, int2 f
|
|||
return input[size_t(texel.y) * size.x + texel.x];
|
||||
}
|
||||
|
||||
static void jump_flooding_pass(Array<int2> &input, Array<int2> &output, int2 size, int step_size)
|
||||
static void jump_flooding_pass(Span<int2> input,
|
||||
MutableSpan<int2> output,
|
||||
int2 size,
|
||||
int step_size)
|
||||
{
|
||||
threading::parallel_for(IndexRange(size.y), 1, [&](const IndexRange sub_y_range) {
|
||||
for (const int64_t y : sub_y_range) {
|
||||
|
@ -79,13 +82,13 @@ static void jump_flooding_pass(Array<int2> &input, Array<int2> &output, int2 siz
|
|||
});
|
||||
}
|
||||
|
||||
Array<int2> jump_flooding(Array<int2> &input, int2 size)
|
||||
Array<int2> jump_flooding(Span<int2> input, int2 size)
|
||||
{
|
||||
Array<int2> initial_flooded_result = Array<int2>(size_t(size.x) * size.y);
|
||||
Array<int2> initial_flooded_result(size_t(size.x) * size.y);
|
||||
jump_flooding_pass(input, initial_flooded_result, size, 1);
|
||||
|
||||
Array<int2> *result_to_flood = &initial_flooded_result;
|
||||
Array<int2> intermediate_result = Array<int2>(size_t(size.x) * size.y);
|
||||
Array<int2> intermediate_result(size_t(size.x) * size.y);
|
||||
Array<int2> *result_after_flooding = &intermediate_result;
|
||||
|
||||
const int max_size = math::max(size.x, size.y);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "BLI_array.hh"
|
||||
#include "BLI_math_vector_types.hh"
|
||||
#include "BLI_span.hh"
|
||||
|
||||
/* Exact copies of the functions in gpu_shader_compositor_jump_flooding_lib.glsl and
|
||||
* COM_algorithm_jump_flooding.hh but adapted for CPU. See those files for more information. */
|
||||
|
@ -18,6 +19,6 @@ int2 encode_jump_flooding_value(int2 closest_seed_texel, bool is_flooded);
|
|||
|
||||
int2 initialize_jump_flooding_value(int2 texel, bool is_seed);
|
||||
|
||||
Array<int2> jump_flooding(Array<int2> &input, int2 size);
|
||||
Array<int2> jump_flooding(Span<int2> input, int2 size);
|
||||
|
||||
} // namespace blender::compositor
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include "BLI_math_vector.hh"
|
||||
#include "BLI_math_vector_types.hh"
|
||||
#include "BLI_span.hh"
|
||||
OmarEmaraDev marked this conversation as resolved
Outdated
|
||||
#include "BLI_task.hh"
|
||||
|
||||
#include "COM_DoubleEdgeMaskOperation.h"
|
||||
|
@ -33,8 +33,8 @@ static float load_mask(const float *input, int2 texel, int2 size, float fallback
|
|||
|
||||
void DoubleEdgeMaskOperation::compute_boundary(const float *inner_mask,
|
||||
const float *outer_mask,
|
||||
Array<int2> &inner_boundary,
|
||||
Array<int2> &outer_boundary)
|
||||
MutableSpan<int2> inner_boundary,
|
||||
MutableSpan<int2> outer_boundary)
|
||||
{
|
||||
const int2 size = int2(this->get_width(), this->get_height());
|
||||
threading::parallel_for(IndexRange(size.y), 1, [&](const IndexRange sub_y_range) {
|
||||
|
@ -87,8 +87,8 @@ void DoubleEdgeMaskOperation::compute_boundary(const float *inner_mask,
|
|||
|
||||
void DoubleEdgeMaskOperation::compute_gradient(const float *inner_mask_buffer,
|
||||
const float *outer_mask_buffer,
|
||||
Array<int2> &flooded_inner_boundary,
|
||||
Array<int2> &flooded_outer_boundary,
|
||||
MutableSpan<int2> flooded_inner_boundary,
|
||||
MutableSpan<int2> flooded_outer_boundary,
|
||||
float *output_mask)
|
||||
{
|
||||
const int2 size = int2(this->get_width(), this->get_height());
|
||||
|
@ -128,8 +128,8 @@ void DoubleEdgeMaskOperation::compute_double_edge_mask(const float *inner_mask,
|
|||
float *output_mask)
|
||||
{
|
||||
const int2 size = int2(this->get_width(), this->get_height());
|
||||
Array<int2> inner_boundary = Array<int2>(size_t(size.x) * size.y);
|
||||
Array<int2> outer_boundary = Array<int2>(size_t(size.x) * size.y);
|
||||
Array<int2> inner_boundary(size_t(size.x) * size.y);
|
||||
OmarEmaraDev marked this conversation as resolved
Outdated
Hans Goudey
commented
Can be written more simply as
Can be written more simply as
```
Array<int2> inner_boundary(size_t(size.x) * size.y);
|
||||
Array<int2> outer_boundary(size_t(size.x) * size.y);
|
||||
compute_boundary(inner_mask, outer_mask, inner_boundary, outer_boundary);
|
||||
Array<int2> flooded_inner_boundary = jump_flooding(inner_boundary, size);
|
||||
Array<int2> flooded_outer_boundary = jump_flooding(outer_boundary, size);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "BLI_span.hh"
|
||||
|
||||
#include "COM_MultiThreadedOperation.h"
|
||||
|
||||
namespace blender::compositor {
|
||||
|
@ -28,13 +30,13 @@ class DoubleEdgeMaskOperation : public NodeOperation {
|
|||
|
||||
void compute_boundary(const float *inner_mask,
|
||||
const float *outer_mask,
|
||||
Array<int2> &inner_boundary,
|
||||
Array<int2> &outer_boundary);
|
||||
MutableSpan<int2> inner_boundary,
|
||||
MutableSpan<int2> outer_boundary);
|
||||
|
||||
void compute_gradient(const float *inner_mask_buffer,
|
||||
const float *outer_mask_buffer,
|
||||
Array<int2> &flooded_inner_boundary,
|
||||
Array<int2> &flooded_outer_boundary,
|
||||
MutableSpan<int2> flooded_inner_boundary,
|
||||
MutableSpan<int2> flooded_outer_boundary,
|
||||
float *output_mask);
|
||||
|
||||
void compute_double_edge_mask(const float *inner_mask,
|
||||
|
|
Loading…
Reference in New Issue
BLI_math_vector.hh
includesBLI_math_vector_types.hh
out of necessity, no need to write them both here