20 b.use_custom_socket_order();
21 b.allow_any_socket_order();
23 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
27 .structure_type(StructureType::Dynamic)
28 .align_with_previous();
34 .description(
"The size of the inpaint in pixels");
63 flooded_boundary, filled_region, distance_to_boundary, smoothing_radius);
82 if (this->
context().use_gpu()) {
109 return inpainting_boundary;
130 bool has_transparent_neighbors = false;
131 constexpr float alpha_threshold = 1.0f - 1e-3f;
132 for (int j = -1; j <= 1; j++) {
133 for (int i = -1; i <= 1; i++) {
134 int2 offset = int2(i, j);
137 if (offset != int2(0)) {
138 if (input.load_pixel_extended<Color>(texel + offset).a < alpha_threshold) {
139 has_transparent_neighbors = true;
148 bool is_boundary_pixel = is_opaque && has_transparent_neighbors;
153 boundary.store_pixel(texel, jump_flooding_value);
163 Result &distance_to_boundary,
166 if (this->
context().use_gpu()) {
168 flooded_boundary, filled_region, distance_to_boundary, smoothing_radius);
172 flooded_boundary, filled_region, distance_to_boundary, smoothing_radius);
178 Result &distance_to_boundary,
213 Result &distance_to_boundary_image,
214 Result &smoothing_radius_image)
229 float4 color = float4(input.load_pixel<Color>(texel));
232 constexpr float alpha_threshold = 1.0f - 1e-3f;
233 if (color.w >= alpha_threshold) {
234 filled_region.store_pixel(texel, Color(color));
235 smoothing_radius_image.store_pixel(texel, 0.0f);
236 distance_to_boundary_image.store_pixel(texel, 0.0f);
242 distance_to_boundary_image.
store_pixel(texel, distance_to_boundary);
252 float blur_window_size =
math::min(
float(max_distance), distance_to_boundary) /
254 bool skip_smoothing = distance_to_boundary > (max_distance * 2.0f);
255 float smoothing_radius = skip_smoothing ? 0.0f : blur_window_size;
256 smoothing_radius_image.
store_pixel(texel, smoothing_radius);
268 const Result &distance_to_boundary)
270 if (this->
context().use_gpu()) {
279 const Result &distance_to_boundary)
294 output.allocate_texture(domain);
307 const Result &distance_to_boundary_image)
315 output.allocate_texture(domain);
318 float4 color = float4(input.load_pixel<Color>(texel));
321 constexpr float alpha_threshold = 1.0f - 1e-3f;
322 if (color.w >= alpha_threshold) {
323 output.store_pixel(texel, Color(color));
327 float distance_to_boundary = distance_to_boundary_image.
load_pixel<
float>(texel);
331 if (distance_to_boundary > max_distance) {
362 ntype.
ui_description =
"Extend borders of an image into transparent or masked regions";
#define NODE_CLASS_OP_FILTER
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Result create_result(ResultType type, ResultPrecision precision)
gpu::Shader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Context & context() const
Result & get_input(StringRef identifier) const
virtual Domain compute_domain()
bool is_single_value() const
void store_pixel(const int2 &texel, const T &pixel_value)
void allocate_texture(const Domain domain, const bool from_pool=true, const std::optional< ResultStorageType > storage_type=std::nullopt)
void unbind_as_texture() const
void bind_as_texture(gpu::Shader *shader, const char *texture_name) const
T load_pixel_extended(const int2 &texel) const
T load_pixel(const int2 &texel) const
void unbind_as_image() const
void bind_as_image(gpu::Shader *shader, const char *image_name, bool read=false) const
StructureType structure_type
NodeOperation(Context &context, const bNode &node)
void fill_inpainting_region(const Result &flooded_boundary, Result &filled_region, Result &distance_to_boundary, Result &smoothing_radius)
Result compute_inpainting_boundary()
void compute_inpainting_region_gpu(const Result &inpainted_region, const Result &distance_to_boundary)
void compute_inpainting_region_cpu(const Result &inpainted_region, const Result &distance_to_boundary_image)
void fill_inpainting_region_cpu(const Result &flooded_boundary, Result &filled_region, Result &distance_to_boundary_image, Result &smoothing_radius_image)
void fill_inpainting_region_gpu(const Result &flooded_boundary, Result &filled_region, Result &distance_to_boundary, Result &smoothing_radius)
Result compute_inpainting_boundary_gpu()
void compute_inpainting_region(const Result &inpainted_region, const Result &distance_to_boundary)
Result compute_inpainting_boundary_cpu()
void node_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
ColorSceneLinear4f< eAlpha::Premultiplied > Color
int2 initialize_jump_flooding_value(const int2 &texel, const bool is_seed)
void symmetric_separable_blur_variable_size(Context &context, const Result &input, const Result &radius, Result &output, const int weights_resolution=128, const math::FilterKernel filter_type=math::FilterKernel::Gauss)
void jump_flooding(Context &context, Result &input, Result &output)
void parallel_for(const int2 range, const Function &function)
T distance(const T &a, const T &b)
T min(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T max(const T &a, const T &b)
static void node_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void node_register()
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(gpu::Shader *sh, const char *name, int value)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
const char * enum_name_legacy
NodeDeclareFunction declare